File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change 1+ // RUN: %clang_msan -Wno-alloc-size -fsanitize-recover=memory %s -o %t && not %run %t 2>&1 | FileCheck %s
2+
3+ // MSan doesn't catch this because internally it translates 0-byte allocations
4+ // into 1-byte
5+ // XFAIL: *
6+
7+ #include < malloc.h>
8+ #include < stdio.h>
9+
10+ int main (int argc, char **argv) {
11+ {
12+ char *p1 = (char *)calloc (1 , 0 );
13+ printf (" p1 is %p\n " , p1);
14+ printf (" Content of p1 is: %d\n " , *p1);
15+ // CHECK: WARNING: MemorySanitizer: use-of-uninitialized-value
16+ // CHECK: {{#0 0x.* in main .*zero_alloc.cpp:}}[[@LINE-2]]
17+ free (p1);
18+ }
19+
20+ {
21+ char *p2 = (char *)calloc (0 , 1 );
22+ printf (" p2 is %p\n " , p2);
23+ printf (" Content of p2 is: %d\n " , *p2);
24+ // CHECK: WARNING: MemorySanitizer: use-of-uninitialized-value
25+ // CHECK: {{#0 0x.* in main .*zero_alloc.cpp:}}[[@LINE-2]]
26+ free (p2);
27+ }
28+
29+ {
30+ char *p3 = (char *)malloc (0 );
31+ printf (" p3 is %p\n " , p3);
32+ printf (" Content of p2 is: %d\n " , *p3);
33+ // CHECK: WARNING: MemorySanitizer: use-of-uninitialized-value
34+ // CHECK: {{#0 0x.* in main .*zero_alloc.cpp:}}[[@LINE-2]]
35+ free (p3);
36+ }
37+
38+ return 0 ;
39+ }
You can’t perform that action at this time.
0 commit comments