Pregunta

I've just tried out GCC 4.8's new exciting feature AddressSanitizer.

The program

#include <iostream>
int main(int argc, const char * argv[], const char * envp[]) {
    int *x = nullptr;
    int y = *x;
    std::cout << y << std::endl;
    return 0;
}

compile find using

g++-4.8 -std=gnu++0x -g -fsanitize=address -fno-omit-frame-pointer -Wall ~/h.cpp -o h

but when I run the program I get

ASAN:SIGSEGV
=================================================================
==7531== ERROR: AddressSanitizer crashed on unknown address 0x000000000000 (pc 0x000000400aac sp 0x7fff11ce0fd0 bp 0x7fff11ce1000 T0)
AddressSanitizer can not provide additional info.
    #0 0x400aab (/home/per/h+0x400aab)
    #1 0x7fc432e1b76c (/lib/x86_64-linux-gnu/libc-2.15.so+0x2176c)
Stats: 0M malloced (0M for red zones) by 0 calls
Stats: 0M realloced by 0 calls
Stats: 0M freed by 0 calls
Stats: 0M really freed by 0 calls
Stats: 0M (0 full pages) mmaped in 0 calls
  mmaps   by size class: 
  mallocs by size class: 
  frees   by size class: 
  rfrees  by size class: 
Stats: malloc large: 0 small slow: 0

This seems like an incorrect way to report a memory error. Have I missed some compilation or link flags?

¿Fue útil?

Solución

This is the intended way to report a NULL dereference. You can run the program output through asan_symbolize.py (should be present in your GCC tree) to get symbol names and line numbers in the source file.

Otros consejos

I cannot find any asan_symbolize.py on gcc 4.8 nor 4.9. I added a workaround at https://code.google.com/p/address-sanitizer/issues/detail?id=223

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top