[vala/0.50] vala: Capturing va_list parameters/variables is not allowed



commit bb8099cd1c45a49604b84240dead3e2fefbff45e
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 c434ac1be..157136c58 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -2150,6 +2150,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".printf (local.get_full_name ()));
+                                               b.error = true;
                                        }
                                }
                        }
@@ -2209,6 +2212,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".printf (param.get_full_name ()));
+                                                       b.error = true;
+                                               }
                                        }
                                }
 
diff --git a/tests/Makefile.am b/tests/Makefile.am
index fccba9159..797db328c 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -955,6 +955,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 b1cc20ada..5d10e3009 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".printf (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'".printf (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".printf (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]