#include <sanitizer/asan_interface.h>
#include <stdio.h>
#include <stdlib.h>
#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
char *heap_ptr;
int main() {
setvbuf(stderr, NULL, _IONBF, 0);
heap_ptr = (char *)malloc(10);
fprintf(stderr, "heap_ptr: " PTR_FMT "\n", heap_ptr);
free(heap_ptr);
free(heap_ptr);
return 0;
}
#if (__APPLE__)
__attribute__((weak))
#endif
extern "C" void
__asan_on_error() {
int present = __asan_report_present();
void *addr = __asan_get_report_address();
const char *description = __asan_get_report_description();
fprintf(stderr, "%s\n", (present == 1) ? "report present" : "");
fprintf(stderr, "addr: " PTR_FMT "\n", addr);
fprintf(stderr, "description: %s\n", description);
}