[asan] don't return from a never-return function. fix a test that had a chain of bugs instead of just one

llvm-svn: 160719
This commit is contained in:
Kostya Serebryany 2012-07-25 10:56:09 +00:00
parent c145b02607
commit bb0ade6daa
2 changed files with 10 additions and 12 deletions

View File

@ -387,9 +387,15 @@ void NOINLINE __asan_set_error_report_callback(void (*callback)(const char*)) {
void __asan_report_error(uptr pc, uptr bp, uptr sp, void __asan_report_error(uptr pc, uptr bp, uptr sp,
uptr addr, bool is_write, uptr access_size) { uptr addr, bool is_write, uptr access_size) {
// Do not print more than one report, otherwise they will mix up.
static atomic_uint32_t num_calls; static atomic_uint32_t num_calls;
if (atomic_fetch_add(&num_calls, 1, memory_order_relaxed) != 0) return; if (atomic_fetch_add(&num_calls, 1, memory_order_relaxed) != 0) {
// Do not print more than one report, otherwise they will mix up.
// We can not return here because the function is marked as never-return.
AsanPrintf("AddressSanitizer: while reporting a bug found another one."
"Ignoring.\n");
SleepForSeconds(5);
Die();
}
AsanPrintf("====================================================" AsanPrintf("===================================================="
"=============\n"); "=============\n");

View File

@ -670,20 +670,12 @@ TEST(AddressSanitizerInterface, DISABLED_InvalidPoisonAndUnpoisonCallsTest) {
} }
static void ErrorReportCallbackOneToZ(const char *report) { static void ErrorReportCallbackOneToZ(const char *report) {
int len = strlen(report); write(2, "ABCDEF", 6);
char *dup = (char*)malloc(len);
strcpy(dup, report);
for (int i = 0; i < len; i++) {
if (dup[i] == '1') dup[i] = 'Z';
}
int written = write(2, dup, len);
ASSERT_EQ(len, written);
free(dup);
} }
TEST(AddressSanitizerInterface, SetErrorReportCallbackTest) { TEST(AddressSanitizerInterface, SetErrorReportCallbackTest) {
__asan_set_error_report_callback(ErrorReportCallbackOneToZ); __asan_set_error_report_callback(ErrorReportCallbackOneToZ);
EXPECT_DEATH(__asan_report_error(0, 0, 0, 0, true, 1), "size Z"); EXPECT_DEATH(__asan_report_error(0, 0, 0, 0, true, 1), "ABCDEF");
__asan_set_error_report_callback(NULL); __asan_set_error_report_callback(NULL);
} }