]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Do not allow to change .length of arrays with fixed length
authorFlorian Brosch <flo.brosch@gmail.com>
Wed, 17 Sep 2014 12:45:52 +0000 (14:45 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Thu, 7 Nov 2019 11:11:48 +0000 (12:11 +0100)
This would result in invalid C code.

tests/arrays/fixed-length-read-only-length.test [new file with mode: 0644]
vala/valaassignment.vala

diff --git a/tests/arrays/fixed-length-read-only-length.test b/tests/arrays/fixed-length-read-only-length.test
new file mode 100644 (file)
index 0000000..b53eb11
--- /dev/null
@@ -0,0 +1,6 @@
+Invalid Code
+
+void main () {
+       int foo[2] = { 23, 42 };
+       foo.length = 3;
+}
index 91bcee308705741d54d3fb1725894c5ec16641a0..532dac240b603e29dd10255a875217cb39fafd12 100644 (file)
@@ -292,6 +292,10 @@ public class Vala.Assignment : Expression {
                                                return false;
                                        }
                                }
+                       } else if (ma.symbol_reference is ArrayLengthField && ((ArrayType) ma.inner.value_type).inline_allocated) {
+                               error = true;
+                               Report.error (source_reference, "`length' field of fixed length arrays is read-only");
+                               return false;
                        } else if (ma.symbol_reference is Variable && right.value_type == null) {
                                var variable = (Variable) ma.symbol_reference;