地址清洁剂的否定性?

问题描述:

考虑下面的代码。当我使用地址清理器进行编译和运行时,不显示任何错误。但是应该有一个错误权限,即分配/访问越界存储位置?为什么不解决卫生洗涤剂检测?地址清洁剂的否定性?

int arr[30]; 

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

谢谢!

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

这是由以下条目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). 
+0

但是即使我做INT改编[30]地方,而不是全球性的,它不会引发错误。即使使用-fno-common也不会引发错误。 –

+0

当然,这就是A1所要解决的问题。基本上GCC前端是“聪明的”,足以在ASan有机会介入之前尽早丢弃显然不好的访问。 – yugr