Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DataflowSanitizer] Use nullptr instead of NULL or 0 #85986

Closed
wants to merge 1 commit into from

Conversation

ghost
Copy link

@ghost ghost commented Mar 20, 2024

No description provided.

Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot
Copy link
Collaborator

llvmbot commented Mar 20, 2024

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

Author: LL (matrixificiation)

Changes

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 --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);
   }

Copy link

⚠️ We detected that you are using a GitHub private e-mail address to contribute to the repo.
Please turn off Keep my email addresses private setting in your account.
See LLVM Discourse for more information.

Copy link

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff 891172d9be01dd7c7e5298f2d8fdb143add448da c1142da8557b5c32eef0b0122fee4552911b48ea -- compiler-rt/lib/dfsan/dfsan_allocator.cpp
View the diff from clang-format here.
diff --git a/compiler-rt/lib/dfsan/dfsan_allocator.cpp b/compiler-rt/lib/dfsan/dfsan_allocator.cpp
index d382501eb9..282e523345 100644
--- a/compiler-rt/lib/dfsan/dfsan_allocator.cpp
+++ b/compiler-rt/lib/dfsan/dfsan_allocator.cpp
@@ -91,47 +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;
-}
+      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 (AllocatorMayReturnNull())
+      return nullptr;
 
-if (AllocatorMayReturnNull())
-  return nullptr;
+    if (AllocatorMayReturnNull())
+      return nullptr;
 
-if (!p)
-  return nullptr;
+    if (!p)
+      return nullptr;
 
-if (!beg)
-  return nullptr;
+    if (!beg)
+      return nullptr;
 
-if (!b)
-  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 (!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;
 
-if (AllocatorMayReturnNull())
-  return nullptr;
+    if (AllocatorMayReturnNull())
+      return nullptr;
 
-if (AllocatorMayReturnNull())
-  return nullptr;
+    if (AllocatorMayReturnNull())
+      return nullptr;
 
     BufferedStackTrace stack;
     ReportRssLimitExceeded(&stack);

Repository owner closed this by deleting the head repository Mar 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants