[compiler-rt] [asan] Add test for deferencing zero-sized malloc/calloc (PR #155933)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 28 15:21:40 PDT 2025
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff origin/main HEAD --extensions cpp -- compiler-rt/test/asan/TestCases/zero_alloc.cpp
``````````
:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/compiler-rt/test/asan/TestCases/zero_alloc.cpp b/compiler-rt/test/asan/TestCases/zero_alloc.cpp
index 3decd5acb..832b35395 100644
--- a/compiler-rt/test/asan/TestCases/zero_alloc.cpp
+++ b/compiler-rt/test/asan/TestCases/zero_alloc.cpp
@@ -7,30 +7,30 @@
int main(int argc, char **argv) {
{
- char* p1 = (char*)calloc(1, 0);
- printf ("p1 is %p\n", p1);
- printf ("Content of p1 is: %d\n", *p1);
- // CHECK: ERROR: AddressSanitizer: heap-buffer-overflow
- // CHECK: {{#0 0x.* in main .*zero_alloc.cpp:}}[[@LINE-2]]
- free(p1);
+ char *p1 = (char *)calloc(1, 0);
+ printf("p1 is %p\n", p1);
+ printf("Content of p1 is: %d\n", *p1);
+ // CHECK: ERROR: AddressSanitizer: heap-buffer-overflow
+ // CHECK: {{#0 0x.* in main .*zero_alloc.cpp:}}[[@LINE-2]]
+ free(p1);
}
{
- char* p2 = (char*)calloc(0, 1);
- printf ("p2 is %p\n", p2);
- printf ("Content of p2 is: %d\n", *p2);
- // CHECK: ERROR: AddressSanitizer: heap-buffer-overflow
- // CHECK: {{#0 0x.* in main .*zero_alloc.cpp:}}[[@LINE-2]]
- free(p2);
+ char *p2 = (char *)calloc(0, 1);
+ printf("p2 is %p\n", p2);
+ printf("Content of p2 is: %d\n", *p2);
+ // CHECK: ERROR: AddressSanitizer: heap-buffer-overflow
+ // CHECK: {{#0 0x.* in main .*zero_alloc.cpp:}}[[@LINE-2]]
+ free(p2);
}
{
- char* p3 = (char*)malloc(0);
- printf ("p3 is %p\n", p3);
- printf ("Content of p2 is: %d\n", *p3);
- // CHECK: ERROR: AddressSanitizer: heap-buffer-overflow
- // CHECK: {{#0 0x.* in main .*zero_alloc.cpp:}}[[@LINE-2]]
- free(p3);
+ char *p3 = (char *)malloc(0);
+ printf("p3 is %p\n", p3);
+ printf("Content of p2 is: %d\n", *p3);
+ // CHECK: ERROR: AddressSanitizer: heap-buffer-overflow
+ // CHECK: {{#0 0x.* in main .*zero_alloc.cpp:}}[[@LINE-2]]
+ free(p3);
}
return 0;
``````````
</details>
https://github.com/llvm/llvm-project/pull/155933
More information about the llvm-commits
mailing list