#include <sanitizer/asan_interface.h>
#include <stdio.h>
#include <stdlib.h>
int main() {
setvbuf(stderr, NULL, _IONBF, 0);
char *heap_ptr = (char *)malloc(10);
free(heap_ptr);
int present = __asan_report_present();
fprintf(stderr, "%s\n", (present == 0) ? "no report" : "");
heap_ptr[0] = 'A';
return 0;
}
#ifdef _WIN32
# ifdef _WIN64
# define PTR_FMT "0x%08llx"
# else
# define PTR_FMT "0x%08x"
# endif
#elif defined(__sun__) && defined(__svr4__)
# define PTR_FMT "0x%p"
#else
# define PTR_FMT "%p"
#endif
#if (__APPLE__)
__attribute__((weak))
#endif
extern "C" void
__asan_on_error() {
int present = __asan_report_present();
void *pc = __asan_get_report_pc();
void *bp = __asan_get_report_bp();
void *sp = __asan_get_report_sp();
void *addr = __asan_get_report_address();
int is_write = __asan_get_report_access_type();
size_t access_size = __asan_get_report_access_size();
const char *description = __asan_get_report_description();
fprintf(stderr, "%s\n", (present == 1) ? "report" : "");
fprintf(stderr, "pc: " PTR_FMT "\n", pc);
fprintf(stderr, "bp: " PTR_FMT "\n", bp);
fprintf(stderr, "sp: " PTR_FMT "\n", sp);
fprintf(stderr, "addr: " PTR_FMT "\n", addr);
fprintf(stderr, "type: %s\n", (is_write ? "write" : "read"));
fprintf(stderr, "access_size: %ld\n", access_size);
fprintf(stderr, "description: %s\n", description);
}