From: Florian Brosch Date: Wed, 17 Sep 2014 12:45:52 +0000 (+0200) Subject: vala: Do not allow to change .length of arrays with fixed length X-Git-Tag: 0.44.10~17 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1046e3be73a85de301b41f7f977c02d5c2409ae7;p=thirdparty%2Fvala.git vala: Do not allow to change .length of arrays with fixed length This would result in invalid C code. --- diff --git a/tests/arrays/fixed-length-read-only-length.test b/tests/arrays/fixed-length-read-only-length.test new file mode 100644 index 000000000..b53eb112a --- /dev/null +++ b/tests/arrays/fixed-length-read-only-length.test @@ -0,0 +1,6 @@ +Invalid Code + +void main () { + int foo[2] = { 23, 42 }; + foo.length = 3; +} diff --git a/vala/valaassignment.vala b/vala/valaassignment.vala index 91bcee308..532dac240 100644 --- a/vala/valaassignment.vala +++ b/vala/valaassignment.vala @@ -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;