Issue 83730
Summary No warning reported for buffer overflow in Clang
Labels clang
Assignees
Reporter mushenoy
    Buffer overflow in the below scenario is not detected in Clang. 
GCC reports warning for the same program.

Sample program
```
#include <string.h>

char d[3];
void test (int i)
{
  const char *s = i < 0 ? "12345678" : "87654321";
  strcat (d, s);
}
```

Compilation with Clang:
No warnings reported
```
# clang -c -Wall prog.c
#
```

Compilation with GCC:
```
# gcc -c -Wall prog.c
prog.c: In function test:
prog.c:7:3: warning: strcat writing 9 bytes into a region of size 3 overflows the destination [-Wstringop-overflow=]
    7 |   strcat (d, s);
      |   ^~~~~~~~~~~~~
prog.c:3:6: note: destination object d of size 3
    3 | char d[3];
      |      ^
```

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

Reply via email to