This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/83429] Incorrect line number reported by -Wformat-truncation
- From: "bugzilla at poradnik-webmastera dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 15 Dec 2017 09:00:32 +0000
- Subject: [Bug c++/83429] Incorrect line number reported by -Wformat-truncation
- Auto-submitted: auto-generated
- References: <bug-83429-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83429
--- Comment #1 from Daniel Fruzynski <bugzilla@poradnik-webmastera.com> ---
Another test case, this time "note:" with argument range also points to
incorrect line:
[code]
#include <stdio.h>
struct S
{
unsigned char n;
char out[2];
};
void test(S* s) // line 9
{
snprintf(s->out, sizeof(s->out), "%d", s->n); // line 11
}
[/code]
[out]
test.cc: In function ‘void test(S*)’:
test.cc:9:6: warning: ‘%d’ directive output may be truncated writing between 1
and 3 bytes into a region of size 2 [-Wformat-truncation=]
void test(S* s) // line 9
^~~~
test.cc:9:6: note: directive argument in the range [0, 255]
test.cc:11:13: note: ‘snprintf’ output between 2 and 4 bytes into a destination
of size 2
snprintf(s->out, sizeof(s->out), "%d", s->n); // line 11
~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[/out]