3 ms·
Just for fun, type in this program: int fred(int a[10]) { return a[11]; } It compiles without error with gcc and clang, even with -Wall. The c
by WalterBright 8y ago
Just for fun, type in this program:
int fred(int a[10]) {
return a[11];
}
It compiles without error with gcc and clang, even with -Wall. The code generated by clang is:
mov EAX,02Ch[RDI]
ret
i.e. buffer overflow, even though the array size is given. Compile the equivalent DasBetterC program:
int fred(ref int[10] a) {
return a[11];
}
fred.d(2): Error: array index 11 is out of bounds a[0 .. 10]
And the 32 bit code generated (when using 9 instead of 11 so it will compile):
mov EAX,024h[EAX]
ret