Issue |
90117
|
Summary |
-Wfree-nonheap-object doesn't warn when free() is used on a pointer to an array
|
Labels |
new issue
|
Assignees |
|
Reporter |
dzhigit1
|
```
$ clang-18 -v
Debian clang version 18.1.4 (1)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/13
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/14
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/14
Candidate multilib: .;@m64
Selected multilib: .;@m64
$ cat test.c
#include <stdlib.h>
int
main(void)
{
char *a = "";
free(a);
return 0;
}
$ gcc -pipe -Wfree-nonheap-object -o test test.c
test.c: In function ‘main’:
test.c:7:3: warning: ‘free’ called on a pointer to an unallocated object ‘""’ [-Wfree-nonheap-object]
7 | free(a);
| ^~~~~~~
test.c:6:9: note: assigned here
6 | char *a = "";
| ^
$ clang-18 -pipe -Wfree-nonheap-object -o test test.c
$ ./test
free(): invalid pointer
Аварийный останов
```
...
```
$ cat test2.c
#include <stdlib.h>
int
main(void)
{
int *a, b[1];
a = b;
free(a);
return 0;
}
$ gcc -pipe -Wfree-nonheap-object -o test2 test2.c
test2.c: In function ‘main’:
test2.c:8:3: warning: ‘free’ called on unallocated object ‘b’ [-Wfree-nonheap-object]
8 | free(a);
| ^~~~~~~
test2.c:6:11: note: declared here
6 | int *a, b[1];
| ^
$ clang-18 -pipe -Wfree-nonheap-object -o test2 test2.c
$ ./test2
free(): invalid pointer
Аварийный останов
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs