1
votes

Consider the code below. No error is shown when I compile and run it with address sanitizer. But there should be an error right i.e assigning/accessing out of bounds memory location? Why doesn't address sanitizer detect it?

int arr[30];

int main(){
    arr[40] = 34;
    printf(ā€œ%dā€, arr[40]);
}

Thanks!

clang -fsanitize=address -fno-omit-frame-pointer test.c
./a.out
1

1 Answers

3
votes

This is described by the following entry in FAQ:

Q: Why didn't ASan report an obviously invalid memory access in my code?

A1: If your errors is too obvious, compiler might have already optimized it 
    out by the time Asan runs.

A2: Another, C-only option is accesses to global common symbols which are
    not protected by Asan (you can use -fno-common to disable generation of
    common symbols and hopefully detect more bugs).