[compiler-rt] [ASan][Windows] Fix false positive for zero sized rtl allocations (PR #181015)

David Justo via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 13 11:32:56 PST 2026


================
@@ -1125,6 +1150,14 @@ uptr asan_malloc_usable_size(const void *ptr, uptr pc, uptr bp) {
     GET_STACK_TRACE_FATAL(pc, bp);
     ReportMallocUsableSizeNotOwned((uptr)ptr, &stack);
   }
+#if SANITIZER_WINDOWS
+  // Zero-size allocations are internally upgraded to size 1, but we should
+  // report the originally requested size (0) to the user via
+  // HeapSize/RtlSizeHeap.
----------------
davidmrdavid wrote:

nit - since we're doing something weird (upgrading zero-size allocations to 1, then back to zero), let's call out why we upgraded them in the first place.

```suggestion
  // For backwards compatibility (`malloc(0)` may return a non-null pointer),
  // zero-sized allocations are internally upgraded to size 1 (so ASan can error if they're dereferenced!).
  // However, we report size `0` when the size is requested through `HeapSize`  / `RtlSizeHeap`
```

https://github.com/llvm/llvm-project/pull/181015


More information about the llvm-commits mailing list