Vala's pointer based generics system should not compile when used with an array of value types
Submitted by fsb..@..dex.ru
Link to original bug (#792534)
Description
Consider the code:
/* file test.vala */
void main() {
int[] numbers = { 10, 30, 1, 8, -5, 7, 666, 12 };
foreach (int a in numbers) { stdout.printf("%d ", a); }
stdout.printf("\n");
qsort_with_data`<int>`(numbers, sizeof(int), (a, b) => { return a == b ? 0 : a < b ? -1 : 1; });
foreach (int a in numbers) { stdout.printf("%d ", a); }
stdout.printf("\n");
}
If you will compile it with the command:
valac -X -fsanitize=address -X -fsanitize=undefined -X -fsanitize=leak -X -fno-omit-frame-pointer test.vala
You will get the output:
(linux mint, gcc-7, valac 0.36.8)
10 30 1 8 -5 7 666 12
/usr/share/vala-0.36/vapi/glib-2.0.vapi:5714:11: runtime error: load of misaligned address 0x60300000efb4 for type 'const `<unknown>` *', which requires 8 byte alignment
0x60300000efb4: note: pointer points here
0a 00 00 00 1e 00 00 00 01 00 00 00 08 00 00 00 fb ff ff ff 07 00 00 00 9a 02 00 00 0c 00 00 00
^
/usr/share/vala-0.36/vapi/glib-2.0.vapi:5714:11: runtime error: load of misaligned address 0x60300000efc4 for type 'const `<unknown>` *', which requires 8 byte alignment
0x60300000efc4: note: pointer points here
fb ff ff ff 07 00 00 00 0c 00 00 00 9a 02 00 00 02 00 00 00 ff ff ff 02 20 00 00 00 01 00 00 7a
^
-5 1 7 8 10 12 30 666
or if you use FreeBSD, you will get:
0 30 1 8 -5 7 666 12
/root/MyProjects/test.vala.c:68:28: runtime error: load of misaligned address 0x603000000314 for type 'gconstpointer' (aka 'const void *'), which requires 8 byte alignment
0x603000000314: note: pointer points here
0a 00 00 00 1e 00 00 00 01 00 00 00 08 00 00 00 fb ff ff ff 07 00 00 00 9a 02 00 00 0c 00 00 00
^
SUMMARY: AddressSanitizer: undefined-behavior /root/MyProjects/test.vala.c:68:28 in
/root/MyProjects/test.vala.c:68:19: runtime error: load of misaligned address 0x603000000324 for type 'gconstpointer' (aka 'const void *'), which requires 8 byte alignment
0x603000000324: note: pointer points here
fb ff ff ff 07 00 00 00 0c 00 00 00 9a 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
^
SUMMARY: AddressSanitizer: undefined-behavior /root/MyProjects/test.vala.c:68:19 in
-5 1 7 8 10 12 30 666
If you sort arrays with Posix.qsort, you will not receive sanitizer errors.
Version: 0.36.x
See also
Edited by Corentin Noël