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



commit 37b86c74908acaa963330ead837c0a050ed8db1f
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                     | 8 +++++++-
 vala/valafield.vala                        | 6 ++++++
 vala/valamethod.vala                       | 6 ++++++
 vala/valasignal.vala                       | 8 +++++++-
 9 files changed, 58 insertions(+), 2 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index e547c923e..aff3d63d9 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -629,6 +629,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 \
@@ -642,6 +643,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/foreach-iterator-args.test \
        semantic/foreach-iterator-element-owned.test \
@@ -694,6 +696,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 \
@@ -736,6 +739,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 3e79527a8..bcfb1d27a 100644
--- a/vala/valadelegate.vala
+++ b/vala/valadelegate.vala
@@ -267,7 +267,13 @@ public class Vala.Delegate : TypeSymbol, Callable {
                }
                
                return_type.check (context);
-               
+
+               if (return_type.data_type == context.analyzer.va_list_type.data_type) {
+                       error = true;
+                       Report.error (source_reference, "`%s' not supported as return type".printf 
(return_type.data_type.get_full_name ()));
+                       return false;
+               }
+
                foreach (Parameter param in parameters) {
                        param.check (context);
                }
diff --git a/vala/valafield.vala b/vala/valafield.vala
index a9cbb1e33..4f7594e01 100644
--- a/vala/valafield.vala
+++ b/vala/valafield.vala
@@ -106,6 +106,12 @@ public class Vala.Field : Variable, Lockable {
                        return false;
                }
 
+               if (variable_type.data_type == context.analyzer.va_list_type.data_type) {
+                       error = true;
+                       Report.error (source_reference, "`%s' not supported as field type".printf 
(variable_type.data_type.get_full_name ()));
+                       return false;
+               }
+
                variable_type.check (context);
 
                // check whether field type is at least as accessible as the field
diff --git a/vala/valamethod.vala b/vala/valamethod.vala
index 2f7185b2a..6328b0272 100644
--- a/vala/valamethod.vala
+++ b/vala/valamethod.vala
@@ -712,6 +712,12 @@ public class Vala.Method : Subroutine, Callable {
 
                return_type.check (context);
 
+               if (return_type.data_type == context.analyzer.va_list_type.data_type) {
+                       error = true;
+                       Report.error (source_reference, "`%s' not supported as return type".printf 
(return_type.data_type.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 d0a6ac0c3..db92c8592 100644
--- a/vala/valasignal.vala
+++ b/vala/valasignal.vala
@@ -192,7 +192,13 @@ public class Vala.Signal : Symbol, Lockable, Callable {
                checked = true;
 
                return_type.check (context);
-               
+
+               if (return_type.data_type == context.analyzer.va_list_type.data_type) {
+                       error = true;
+                       Report.error (source_reference, "`%s' not supported as return type".printf 
(return_type.data_type.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]