[PATCH] D24391: [asan] Reify ErrorMallocUsableSizeNotOwned
Filipe Cabecinhas via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 13 07:45:43 PDT 2016
filcab updated this revision to Diff 71169.
filcab added a comment.
Updating after https://reviews.llvm.org/D23875 (consistency on constructor args and member order)
Vitaly: I know you approved most of these, but you also said we should revisit them after https://reviews.llvm.org/D23875 lands. Let me know if they're ok to commit or if you still want changes.
https://reviews.llvm.org/D24391
Files:
lib/asan/asan_errors.cc
lib/asan/asan_errors.h
lib/asan/asan_report.cc
Index: lib/asan/asan_report.cc
===================================================================
--- lib/asan/asan_report.cc
+++ lib/asan/asan_report.cc
@@ -365,15 +365,8 @@
void ReportMallocUsableSizeNotOwned(uptr addr, BufferedStackTrace *stack) {
ScopedInErrorReport in_report;
- Decorator d;
- Printf("%s", d.Warning());
- Report("ERROR: AddressSanitizer: attempting to call "
- "malloc_usable_size() for pointer which is "
- "not owned: %p\n", addr);
- Printf("%s", d.EndWarning());
- stack->Print();
- DescribeAddressIfHeap(addr);
- ReportErrorSummary("bad-malloc_usable_size", stack);
+ ErrorMallocUsableSizeNotOwned error(GetCurrentTidOrInvalid(), stack, addr);
+ in_report.ReportError(error);
}
void ReportSanitizerGetAllocatedSizeNotOwned(uptr addr,
Index: lib/asan/asan_errors.h
===================================================================
--- lib/asan/asan_errors.h
+++ lib/asan/asan_errors.h
@@ -160,14 +160,31 @@
void Print();
};
+struct ErrorMallocUsableSizeNotOwned : ErrorBase {
+ // ErrorMallocUsableSizeNotOwned doesn't own the stack trace.
+ const BufferedStackTrace *stack;
+ AddressDescription addr_description;
+ // VS2013 doesn't implement unrestricted unions, so we need a trivial default
+ // constructor
+ ErrorMallocUsableSizeNotOwned() = default;
+ ErrorMallocUsableSizeNotOwned(u32 tid, BufferedStackTrace *stack_, uptr addr)
+ : ErrorBase(tid),
+ stack(stack_),
+ addr_description(addr, /*shouldLockThreadRegistry=*/false) {
+ scariness.Clear();
+ }
+ void Print();
+};
+
// clang-format off
#define ASAN_FOR_EACH_ERROR_KIND(macro) \
macro(StackOverflow) \
macro(DeadlySignal) \
macro(DoubleFree) \
macro(NewDeleteSizeMismatch) \
macro(FreeNotMalloced) \
- macro(AllocTypeMismatch)
+ macro(AllocTypeMismatch) \
+ macro(MallocUsableSizeNotOwned)
// clang-format on
#define ASAN_DEFINE_ERROR_KIND(name) kErrorKind##name,
Index: lib/asan/asan_errors.cc
===================================================================
--- lib/asan/asan_errors.cc
+++ lib/asan/asan_errors.cc
@@ -164,4 +164,17 @@
"ASAN_OPTIONS=alloc_dealloc_mismatch=0\n");
}
+void ErrorMallocUsableSizeNotOwned::Print() {
+ Decorator d;
+ Printf("%s", d.Warning());
+ Report(
+ "ERROR: AddressSanitizer: attempting to call malloc_usable_size() for "
+ "pointer which is not owned: %p\n",
+ addr_description.Address());
+ Printf("%s", d.EndWarning());
+ stack->Print();
+ addr_description.Print();
+ ReportErrorSummary("bad-malloc_usable_size", stack);
+}
+
} // namespace __asan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24391.71169.patch
Type: text/x-patch
Size: 2715 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160913/0fca42a4/attachment.bin>
More information about the llvm-commits
mailing list