I built release 3.1 llvm / compiler-rt / clang release 3.1 and I'm trying to check if -fcatch- undefined -behavior really does nothing. So far no luck. For instance. I compile and run
#include <stdio.h> #include <stdlib.h> int main() { int* x = malloc(sizeof(int) * 10); printf("%d\n", x[20]); return 0; }
with
$ /usr/local/bin/clang -fcatch-undefined-behavior undef_test.c && ./a.out 0
Am I missing something really simple?
Yes: xnot an array.
x
From the documentation :
-fcatch- undefined -behavior. , undefined. , , , Clang undefined. , __builtin_trap() . :Subscript, - , , ., .__builtin_unreachable.llvm __builtin_object_size, , __builtin_object_size , . .
-fcatch- undefined -behavior. , undefined. , , , Clang undefined. , __builtin_trap() . :
__builtin_trap()
, , , : ( malloc), ; (, malloc void*).
malloc
void*
,
int main() { int x[10] = {}; printf("%d\n", x[20]); }
Address Sanitizer.
-fcatch-undefined-behavior . . ABI , .
-fcatch-undefined-behavior
, malloc - , , .
, malloc NULL. , NULL, NULL ( ). , NULL , ( free realloc). , , malloc -tated NULL, undefined.
NULL
free
realloc
, , , malloc .