[Bug tree-optimization/96367] bogus -Wformat-truncation in ILP32

msebor at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Wed Jul 29 16:15:20 GMT 2020


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96367

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|c                           |tree-optimization
     Ever confirmed|0                           |1
             Blocks|                            |85741
      Known to fail|                            |10.2.0, 11.0
   Last reconfirmed|                            |2020-07-29
            Summary|bogus format truncation     |bogus -Wformat-truncation
                   |error on armhf when         |in ILP32
                   |building perf with gcc 10   |
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
The mention of armhf was a helpful clue.  With it I was able to reproduce an
unintended inconsistency between ILP32 and LP64 on the following test case. 
Otherwise, reports without test cases to reproduce the problem are hard to
analyze.  An error alone, without the context and the notes that might follow,
also isn't sufficient.  Especially in this case because it doesn't show which
of the four %s directives it refers to.  In the future please provide the
details requested here: https://gcc.gnu.org/bugs/#need.

$ (set -x && cat t.c && gcc -O2 -S -Wall t.c && gcc -O2 -S -Wall -m32 t.c)
+ cat t.c
char a[8];

void f (const char *s)
{
  __SIZE_TYPE__ n = __builtin_strlen (s);
  if (n < 3) return;

  __builtin_snprintf (a, 8, "%s", s);
}
+ gcc -O2 -S -Wall t.c
+ gcc -O2 -S -Wall -m32 t.c
t.c: In function ‘f’:
t.c:8:30: warning: ‘%s’ directive output may be truncated writing between 3 and
2147483645 bytes into a region of size 8 [-Wformat-truncation=]
    8 |   __builtin_snprintf (a, 8, "%s", s);
      |                              ^~
t.c:8:3: note: ‘__builtin_snprintf’ output between 4 and 2147483646 bytes into
a destination of size 8
    8 |   __builtin_snprintf (a, 8, "%s", s);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85741
[Bug 85741] [meta-bug] bogus/missing -Wformat-overflow


More information about the Gcc-bugs mailing list