]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
valaparser: Don't allow to declare array parameters with "type array[]"
authorRico Tzschichholz <ricotz@ubuntu.com>
Tue, 11 Oct 2016 15:27:01 +0000 (17:27 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Sat, 20 Oct 2018 08:03:19 +0000 (10:03 +0200)
It is required to have a fixed length like "type array[3]".

Fixes https://gitlab.gnome.org/GNOME/vala/issues/163

tests/Makefile.am
tests/basic-types/bug641308.test [new file with mode: 0644]
vala/valaparser.vala

index 64a6e6805986e73ff3eef98a4ad3fc9da4d4432b..0f0c8f0072ddc79cc4ac218f294c77b7ae31aa39 100644 (file)
@@ -40,6 +40,7 @@ TESTS = \
        basic-types/bug604589.test \
        basic-types/bug622178.vala \
        basic-types/bug632322.vala \
+       basic-types/bug641308.test \
        basic-types/bug643612.vala \
        basic-types/bug644046.vala \
        basic-types/bug647222.vala \
diff --git a/tests/basic-types/bug641308.test b/tests/basic-types/bug641308.test
new file mode 100644 (file)
index 0000000..b530077
--- /dev/null
@@ -0,0 +1,7 @@
+Invalid Code
+
+void foo (int i[]) {
+}
+
+void main () {
+}
index f110452b48224893c45ac704984b7f5f098f1d8d..01ad01d2942c39137d4e509d57ea6a13620ebdaf 100644 (file)
@@ -3286,7 +3286,12 @@ public class Vala.Parser : CodeVisitor {
                }
                string id = parse_identifier ();
 
-               type = parse_inline_array_type (type);
+               var array_type = parse_inline_array_type (type);
+               if (!(type is ArrayType) && (array_type is ArrayType) && !((ArrayType) array_type).fixed_length) {
+                       throw new ParseError.SYNTAX ("invalid array parameter declaration");
+               } else {
+                       type = array_type;
+               }
 
                var param = new Parameter (id, type, get_src (begin));
                set_attributes (param, attrs);