[NFC][sanitizer] Early return for empty StackTraces
authorVitaly Buka <vitalybuka@google.com>
Tue, 23 Nov 2021 20:51:12 +0000 (12:51 -0800)
committerVitaly Buka <vitalybuka@google.com>
Tue, 23 Nov 2021 20:53:54 +0000 (12:53 -0800)
Current callers should filter them out anyway,
but with this patch we don't need rely on that assumption.

compiler-rt/lib/sanitizer_common/sanitizer_stack_store.cpp

index 74be6df..9a727d2 100644 (file)
@@ -17,6 +17,8 @@ namespace __sanitizer {
 static constexpr u32 kStackSizeBits = 16;
 
 StackStore::Id StackStore::Store(const StackTrace &trace) {
+  if (!trace.size && !trace.tag)
+    return 0;
   uptr *stack_trace = Alloc(trace.size + 1);
   CHECK_LT(trace.size, 1 << kStackSizeBits);
   *stack_trace = trace.size + (trace.tag << kStackSizeBits);
@@ -25,6 +27,8 @@ StackStore::Id StackStore::Store(const StackTrace &trace) {
 }
 
 StackTrace StackStore::Load(Id id) {
+  if (!id)
+    return {};
   const uptr *stack_trace = reinterpret_cast<const uptr *>(id);
   uptr size = *stack_trace & ((1 << kStackSizeBits) - 1);
   uptr tag = *stack_trace >> kStackSizeBits;