[clang] [-Wunsafe-buffer-usage] Warning Libc functions (PR #101583)
Mikael Holmén via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 6 04:35:26 PDT 2024
mikaelholmen wrote:
Btw a question about the new warning: So with -Wunsafe-buffer-usage-in-libc-call clang now warns on the following?
```
#include <stdio.h>
void foo(void) {
char q[10];
snprintf(q, 10, "%s", "hello");
}
```
It says
```
foo.c:5:3: warning: function 'snprintf' is unsafe [-Wunsafe-buffer-usage-in-libc-call]
5 | snprintf(q, 10, "%s", "hello");
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
foo.c:5:12: note: buffer pointer and size may not match
5 | snprintf(q, 10, "%s", "hello");
| ^
1 warning generated.
```
Is that as expected? If so, how should snprintf be used to avoid the warning?
https://github.com/llvm/llvm-project/pull/101583
More information about the cfe-commits
mailing list