[compiler-rt] [DataflowSanitizer] Use nullptr instead of NULL or 0 (PR #85986)

via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 20 11:38:59 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: LL (matrixificiation)

<details>
<summary>Changes</summary>



---
Full diff: https://github.com/llvm/llvm-project/pull/85986.diff


1 Files Affected:

- (modified) compiler-rt/lib/dfsan/dfsan_allocator.cpp (+42-10) 


``````````diff
diff --git a/compiler-rt/lib/dfsan/dfsan_allocator.cpp b/compiler-rt/lib/dfsan/dfsan_allocator.cpp
index 63475f434cd100..d382501eb991a5 100644
--- a/compiler-rt/lib/dfsan/dfsan_allocator.cpp
+++ b/compiler-rt/lib/dfsan/dfsan_allocator.cpp
@@ -91,16 +91,48 @@ void DFsanThreadLocalMallocStorage::CommitBack() {
 static void *DFsanAllocate(uptr size, uptr alignment, bool zeroise) {
   if (size > max_malloc_size) {
     if (AllocatorMayReturnNull()) {
-      Report("WARNING: DataflowSanitizer failed to allocate 0x%zx bytes\n",
-             size);
-      return nullptr;
-    }
-    BufferedStackTrace stack;
-    ReportAllocationSizeTooBig(size, max_malloc_size, &stack);
-  }
-  if (UNLIKELY(IsRssLimitExceeded())) {
-    if (AllocatorMayReturnNull())
-      return nullptr;
+  Report("WARNING: DataflowSanitizer failed to allocate 0x%zx bytes\n",
+         size);
+  return nullptr;
+}
+
+if (AllocatorMayReturnNull())
+  return nullptr;
+
+if (AllocatorMayReturnNull())
+  return nullptr;
+
+if (AllocatorMayReturnNull())
+  return nullptr;
+
+if (!p)
+  return nullptr;
+
+if (!beg)
+  return nullptr;
+
+if (!b)
+  return nullptr;
+
+if (!ptr)
+  return SetErrnoOnNull(DFsanAllocate(size, sizeof(u64), false /*zeroise*/));
+if (size == 0) {
+  dfsan_deallocate(ptr);
+  return nullptr;
+}
+
+if (AllocatorMayReturnNull())
+  return nullptr;
+
+if (AllocatorMayReturnNull())
+  return nullptr;
+
+if (AllocatorMayReturnNull())
+  return nullptr;
+
+if (AllocatorMayReturnNull())
+  return nullptr;
+
     BufferedStackTrace stack;
     ReportRssLimitExceeded(&stack);
   }

``````````

</details>


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


More information about the llvm-commits mailing list