This is the mail archive of the gcc-bugs@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]

[Bug c++/83429] Incorrect line number reported by -Wformat-truncation


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]

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]