[Bug c/79082] New: -Wformat-truncation inconsistent behaviour
sirl at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Fri Jan 13 12:02:00 GMT 2017
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79082
Bug ID: 79082
Summary: -Wformat-truncation inconsistent behaviour
Product: gcc
Version: 7.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: sirl at gcc dot gnu.org
Target Milestone: ---
This small testcase warns differently for -O0/g/1/2/3 with this "gcc -c
-Wformat-truncation test.c"
extern int snprintf(char *str, __SIZE_TYPE__ size, const char *format, ...);
void test(char *buffer, int val)
{
snprintf(buffer, 3, "%2d", val % 100);
snprintf(buffer, 3, "%2d", (val < 0) ? -(val % 100) : val % 100);
snprintf(buffer, 3, "%2d", __builtin_abs(val % 100));
snprintf(buffer, 3, "%2x", val & 0xff);
}
-O0/1 produce 4 warnings, -O2/3 produce 2 warnings and -Og doesn't warn at all.
I believe it should only ever warn for the first case.
More information about the Gcc-bugs
mailing list