I have a question regarding the catch-undefined-behavior flag in clang. I tried it out in a big project written in C, where at one point, an integer value (i) supplied by the user arrives. I then added the following code:
int arr[3]
arr[i] = 1234;
But when I run the code with gdb it only stops when the variable i has a value of 4 or greater. So when I pass value 3 to i it still accesses the array outside of it's bounds without stopping.
Is this a known limitation of -fcatch-undefined-behavior? Or does it only check if the access is outside of the stack frame, and not outside of local arrays?
Best regards Christian
P.S.: I use clang+llvm 3.0 as compiler/linker. Target is x86. The program runs inside a xubuntu 12.04 virtual machine on a Windows XP box.
Annex J of the ISO C standard lists the following undefined behaviour relevant to your question:
According to your post, Clang's -fcatch-undefined-behavior
seems to only catch the first of those two.