Found by -Werror=array-bounds on ppc64el with gcc 10.2 and musl 1.2
basic_types_arrays.c:1268:2: error: 'memcpy' forming offset [8, 23] is
out of the bounds [0, 8] [-Werror=array-bounds]
1268 | memcpy (dup, self, sizeof (Foo));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Fixes https://gitlab.gnome.org/GNOME/vala/issues/1068
} else if (context.profile == Profile.POSIX) {
// calloc needs stdlib.h
cfile.add_include ("stdlib.h");
+
+ var sizeof_call = new CCodeFunctionCall (new CCodeIdentifier ("sizeof"));
+ sizeof_call.add_argument (new CCodeConstant (get_ccode_name (st)));
+
var creation_call = new CCodeFunctionCall (new CCodeIdentifier ("calloc"));
creation_call.add_argument (new CCodeConstant ("1"));
- creation_call.add_argument (new CCodeIdentifier ("sizeof (%s*)".printf (get_ccode_name (st))));
+ creation_call.add_argument (sizeof_call);
ccode.add_assignment (new CCodeIdentifier ("dup"), creation_call);
}
public int bar;
}
+struct Manam {
+ Bar array[1024];
+ Bar manam;
+}
+
void test_struct_array () {
assert (FOO_ARRAY_CONST[0].bar == 42);
var bar = new Bar[23];
bar[7] = b;
assert (b in bar);
+
+ Manam? manam = {};
+ Manam? manam_copy = manam;
}
void give_fixed_array (out int i[3]) {