Issue |
83776
|
Summary |
Is it possible for Clang to report format truncation warning.
|
Labels |
clang
|
Assignees |
|
Reporter |
mushenoy
|
Clang doesn't report truncation warnings, found with GCC
Sample program:
```
#include <stdio.h>
int main() {
char dst[2];
char src[2] = "a";
snprintf (dst, sizeof (dst), "%s!!", src);
return 0;
}
```
Compilation with Clang:
No warnings reported
```
# clang -c -Wall prog.c
#
```
Compilation with GCC:
```
# gcc -c -Wall prog.c
prog.c: In function main:
prog.c:6:37: warning: !! directive output may be truncated writing 2 bytes into a region of size between 1 and 2 [-Wformat-truncation=]
6 | snprintf (dst, sizeof (dst), "%s!!", src);
| ^~
prog.c:6:5: note: snprintf output between 3 and 4 bytes into a destination of size 2
6 | snprintf (dst, sizeof (dst), "%s!!", src);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```
Compiler Versions:
```
clang version 16.0.6
gcc (GCC) 13.2.1
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs