[vala/wip/issue/884] vala: Don't allow "va_list" as return-type or type of fields



commit 8ee44db879457846294ab80ba17280b228e7e2e9
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Tue Dec 3 13:02:13 2019 +0100

    vala: Don't allow "va_list" as return-type or type of fields
    
    Fixes https://gitlab.gnome.org/GNOME/vala/issues/884

 tests/Makefile.am                          | 4 ++++
 tests/semantic/delegate-return-valist.test | 6 ++++++
 tests/semantic/field-valist.test           | 6 ++++++
 tests/semantic/method-return-valist.test   | 8 ++++++++
 tests/semantic/signal-return-valist.test   | 8 ++++++++
 vala/valadelegate.vala                     | 6 ++++++
 vala/valafield.vala                        | 6 ++++++
 vala/valamethod.vala                       | 6 ++++++
 vala/valasignal.vala                       | 6 ++++++
 9 files changed, 56 insertions(+)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index db87cf3fe..21bfb431e 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -714,6 +714,7 @@ TESTS = \
        semantic/constant-value-type.test \
        semantic/constant-void.test \
        semantic/construct-without-gobject.test \
+       semantic/delegate-return-valist.test \
        semantic/delegate-too-few-type-arguments.test \
        semantic/delegate-too-many-type-arguments.test \
        semantic/enum-empty.test \
@@ -727,6 +728,7 @@ TESTS = \
        semantic/field-non-constant.test \
        semantic/field-owned-to-unowned.test \
        semantic/field-static-instance-access.test \
+       semantic/field-valist.test \
        semantic/field-void.test \
        semantic/floating-reference.vala \
        semantic/foreach-iterator-args.test \
@@ -780,6 +782,7 @@ TESTS = \
        semantic/method-private-virtual.test \
        semantic/method-protected.test \
        semantic/method-return-accessibility.test \
+       semantic/method-return-valist.test \
        semantic/method-too-few-type-arguments.test \
        semantic/method-too-many-type-arguments.test \
        semantic/method-virtual.test \
@@ -822,6 +825,7 @@ TESTS = \
        semantic/signal-detail-non-string.test \
        semantic/struct-derived.test \
        semantic/signal-disconnect-invalid.test \
+       semantic/signal-return-valist.test \
        semantic/struct-field-initializer.test \
        semantic/struct-invalid-base.test \
        semantic/struct-recursive.test \
diff --git a/tests/semantic/delegate-return-valist.test b/tests/semantic/delegate-return-valist.test
new file mode 100644
index 000000000..b8300c952
--- /dev/null
+++ b/tests/semantic/delegate-return-valist.test
@@ -0,0 +1,6 @@
+Invalid Code
+
+delegate va_list Foo ();
+
+void main () {
+}
diff --git a/tests/semantic/field-valist.test b/tests/semantic/field-valist.test
new file mode 100644
index 000000000..9ba207aa0
--- /dev/null
+++ b/tests/semantic/field-valist.test
@@ -0,0 +1,6 @@
+Invalid Code
+
+va_list foo;
+
+void main () {
+}
diff --git a/tests/semantic/method-return-valist.test b/tests/semantic/method-return-valist.test
new file mode 100644
index 000000000..af0d56611
--- /dev/null
+++ b/tests/semantic/method-return-valist.test
@@ -0,0 +1,8 @@
+Invalid Code
+
+va_list foo () {
+       return {};
+}
+
+void main () {
+}
diff --git a/tests/semantic/signal-return-valist.test b/tests/semantic/signal-return-valist.test
new file mode 100644
index 000000000..98aca1313
--- /dev/null
+++ b/tests/semantic/signal-return-valist.test
@@ -0,0 +1,8 @@
+Invalid Code
+
+class Foo : Object {
+       public signal va_list bar ();
+}
+
+void main () {
+}
diff --git a/vala/valadelegate.vala b/vala/valadelegate.vala
index 200b2dbc2..b9db0b287 100644
--- a/vala/valadelegate.vala
+++ b/vala/valadelegate.vala
@@ -311,6 +311,12 @@ public class Vala.Delegate : TypeSymbol, Callable {
 
                return_type.check (context);
 
+               if (return_type.type_symbol == context.analyzer.va_list_type.type_symbol) {
+                       error = true;
+                       Report.error (source_reference, "`%s' not supported as return type".printf 
(return_type.type_symbol.get_full_name ()));
+                       return false;
+               }
+
                foreach (Parameter param in parameters) {
                        param.check (context);
                }
diff --git a/vala/valafield.vala b/vala/valafield.vala
index f3a81f0e3..dc4cde63e 100644
--- a/vala/valafield.vala
+++ b/vala/valafield.vala
@@ -98,6 +98,12 @@ public class Vala.Field : Variable, Lockable {
                        return false;
                }
 
+               if (variable_type.type_symbol == context.analyzer.va_list_type.type_symbol) {
+                       error = true;
+                       Report.error (source_reference, "`%s' not supported as field type".printf 
(variable_type.type_symbol.get_full_name ()));
+                       return false;
+               }
+
                variable_type.check (context);
                if (!external_package) {
                        context.analyzer.check_type (variable_type);
diff --git a/vala/valamethod.vala b/vala/valamethod.vala
index 1be97ab21..b1b4cc77c 100644
--- a/vala/valamethod.vala
+++ b/vala/valamethod.vala
@@ -793,6 +793,12 @@ public class Vala.Method : Subroutine, Callable {
                        context.analyzer.check_type (return_type);
                }
 
+               if (return_type.type_symbol == context.analyzer.va_list_type.type_symbol) {
+                       error = true;
+                       Report.error (source_reference, "`%s' not supported as return type".printf 
(return_type.type_symbol.get_full_name ()));
+                       return false;
+               }
+
                var init_attr = get_attribute ("ModuleInit");
                if (init_attr != null) {
                        source_reference.file.context.module_init_method = this;
diff --git a/vala/valasignal.vala b/vala/valasignal.vala
index 66c7a89c2..c6390c0a3 100644
--- a/vala/valasignal.vala
+++ b/vala/valasignal.vala
@@ -205,6 +205,12 @@ public class Vala.Signal : Symbol, Callable {
 
                return_type.check (context);
 
+               if (return_type.type_symbol == context.analyzer.va_list_type.type_symbol) {
+                       error = true;
+                       Report.error (source_reference, "`%s' not supported as return type".printf 
(return_type.type_symbol.get_full_name ()));
+                       return false;
+               }
+
                foreach (Parameter param in parameters) {
                        if (param.ellipsis) {
                                Report.error  (param.source_reference, "Signals with variable argument lists 
are not supported");


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]