2017-04-21 8 views
1

以下のコードを検討してください。コンパイルしてアドレスサニタイザで実行すると、エラーは表示されません。しかし、境界のメモリ位置の割り当て/アクセスに誤りがあるはずです。なぜサニタイザーはそれを検出しないのでしょうか?アドレス詐称者の偽陰性ですか?

int arr[30]; 

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

ありがとう!

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

答えて

2

これは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型のARRを作る場合でも、[30]ローカル、代わりにグローバルで、それはエラーになりません。 -fno-commonを使用しても、エラーは発生しません。 –

+0

確かに、それは答えA1です。基本的にGCCのフロントエンドは、ASanが介入する前に、明らかに悪いアクセスを早期に捨てるほど "賢い"ものです。 – yugr

関連する問題