This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
| Other format: | [Raw text] | |
$ cat test.c
#include <stdio.h>
int main() {
char buf[3];
snprintf(buf, sizeof buf, "%s", "foo");
return 0;
}
$ gcc -Wformat-truncation -Og ~/test.c
$ gcc -Wformat-truncation -O ~/test.c
test.c: In function ‘main’:
test.c:4:34: warning: ‘snprintf’ output truncated before the last format character [-Wformat-truncation=]
snprintf(buf, sizeof buf, "%s", "foo");
^
test.c:4:5: note: ‘snprintf’ output 4 bytes into a destination of size 3
snprintf(buf, sizeof buf, "%s", "foo");
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Any other optimization level (-O1..3/s/fast) does emit the warning. The documentation makes it clear that the behavior of that warning may be coupled to the optimization level, but this difference between -Og and everything else still looks somewhat odd. Could it be by mistake?
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |