[vala/staging] vala: Capturing va_list parameters/variables is not allowed
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging] vala: Capturing va_list parameters/variables is not allowed
- Date: Tue, 16 Feb 2021 09:33:55 +0000 (UTC)
commit 830d91188c115a775fc5f383f926b483e9a51249
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Tue Feb 16 10:33:06 2021 +0100
vala: Capturing va_list parameters/variables is not allowed
Fixes https://gitlab.gnome.org/GNOME/vala/issues/1136
codegen/valaccodebasemodule.vala | 8 ++++++++
tests/Makefile.am | 2 ++
tests/semantic/member-access-capture-valist-parameter.test | 12 ++++++++++++
tests/semantic/member-access-capture-valist-variable.test | 13 +++++++++++++
vala/valamemberaccess.vala | 9 +++++++++
5 files changed, 44 insertions(+)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 1b67a7172..52d4389e0 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -2200,6 +2200,9 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
if (local.variable_type.is_disposable ()) {
data.add_field (get_ccode_name
(delegate_target_destroy_type), get_delegate_target_destroy_notify_cname (get_local_cname (local)));
}
+ } else if (local.variable_type.type_symbol ==
context.analyzer.va_list_type.type_symbol) {
+ Report.error (local.source_reference, "internal: Capturing
`va_list' variable `%s' is not allowed", local.get_full_name ());
+ b.error = true;
}
}
}
@@ -2259,6 +2262,11 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
foreach (var param in m.get_parameters ()) {
if (param.captured) {
capture_parameter (param, data, block_id);
+
+ if (param.variable_type.type_symbol ==
context.analyzer.va_list_type.type_symbol) {
+ Report.error (param.source_reference, "internal:
Capturing `va_list' parameter `%s' is not allowed", param.get_full_name ());
+ b.error = true;
+ }
}
}
diff --git a/tests/Makefile.am b/tests/Makefile.am
index e7e7e9ced..3294f9a03 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -969,6 +969,8 @@ TESTS = \
semantic/localvariable-void-initializer.test \
semantic/member-access-async-callback-invalid.test \
semantic/member-access-capture-out.test \
+ semantic/member-access-capture-valist-parameter.test \
+ semantic/member-access-capture-valist-variable.test \
semantic/member-access-protected-invalid.test \
semantic/member-access-undefined.test \
semantic/member-access-static-with-instance.vala \
diff --git a/tests/semantic/member-access-capture-valist-parameter.test
b/tests/semantic/member-access-capture-valist-parameter.test
new file mode 100644
index 000000000..6682b2571
--- /dev/null
+++ b/tests/semantic/member-access-capture-valist-parameter.test
@@ -0,0 +1,12 @@
+Invalid Code
+
+delegate void FooFunc ();
+
+void foo (int first, va_list v) {
+ FooFunc f = () => {
+ int arg = v.arg<int> ();
+ };
+}
+
+void main () {
+}
diff --git a/tests/semantic/member-access-capture-valist-variable.test
b/tests/semantic/member-access-capture-valist-variable.test
new file mode 100644
index 000000000..fff299be9
--- /dev/null
+++ b/tests/semantic/member-access-capture-valist-variable.test
@@ -0,0 +1,13 @@
+Invalid Code
+
+delegate void FooFunc ();
+
+void foo (int first, ...) {
+ va_list v = va_list ();
+ FooFunc f = () => {
+ int arg = v.arg<int> ();
+ };
+}
+
+void main () {
+}
diff --git a/vala/valamemberaccess.vala b/vala/valamemberaccess.vala
index 735f1b79e..368f48c88 100644
--- a/vala/valamemberaccess.vala
+++ b/vala/valamemberaccess.vala
@@ -617,6 +617,11 @@ public class Vala.MemberAccess : Expression {
local.captured = true;
block.captured = true;
+
+ if (local.variable_type.type_symbol ==
context.analyzer.va_list_type.type_symbol) {
+ error = true;
+ Report.error (source_reference, "Capturing `va_list' variable `%s' is
not allowed", local.get_full_name ());
+ }
}
} else if (member is Parameter) {
unowned Parameter param = (Parameter) member;
@@ -640,6 +645,10 @@ public class Vala.MemberAccess : Expression {
error = true;
Report.error (source_reference, "Cannot capture reference or output
parameter `%s'", param.get_full_name ());
}
+ if (param.variable_type.type_symbol ==
context.analyzer.va_list_type.type_symbol) {
+ error = true;
+ Report.error (source_reference, "Capturing `va_list' parameter `%s'
is not allowed", param.get_full_name ());
+ }
} else {
unowned PropertyAccessor? acc = param.parent_symbol.parent_symbol as
PropertyAccessor;
if (acc != null && acc !=
context.analyzer.current_method_or_property_accessor && param != acc.prop.this_parameter) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]