1

考虑下面的代码。当我使用地址清理程序编译和运行它时,没有显示错误。但是应该有一个错误,即分配/访问超出范围的内存位置?为什么地址消毒剂没有检测到它?

int arr[30];

int main(){
    arr[40] = 34;
    printf(“%d”, arr[40]);
}

谢谢!

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

1 回答 1

3

常见问题解答中的以下条目对此进行了描述:

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).
于 2017-04-21T04:48:10.173 回答