This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug tree-optimization/80776] -Wformat-overflow false positive for %d on integer bounded by __builtin_unreachable
- From: "jsm28 at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 21 Nov 2017 16:57:28 +0000
- Subject: [Bug tree-optimization/80776] -Wformat-overflow false positive for %d on integer bounded by __builtin_unreachable
- Auto-submitted: auto-generated
- References: <bug-80776-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80776
Joseph S. Myers <jsm28 at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jsm28 at gcc dot gnu.org
--- Comment #2 from Joseph S. Myers <jsm28 at gcc dot gnu.org> ---
The following, reduced from an unsuccessful attempt to avoid a spurious
-Wformat-overflow warning in glibc, produces a spurious warning with current
GCC and looks like the same bug or something very similar.
char buf[15];
void
f (int a, int b, int c, int d, int e, int f)
{
if (a < -999 || a > 9999
|| b < 1 || b > 12
|| c < 1 || c > 31
|| d < 0 || d > 23
|| e < 0 || e > 59
|| f < 0 || f > 60)
__builtin_unreachable ();
__builtin_sprintf (buf, "%04d%02d%02d%02d%02d%02d", a, b, c, d, e, f);
}
u.c: In function 'f':
u.c:13:44: warning: '%02d' directive writing between 2 and 10 bytes into a
region of size 5 [-Wformat-overflow=]
__builtin_sprintf (buf, "%04d%02d%02d%02d%02d%02d", a, b, c, d, e, f);
^~~~
u.c:13:27: note: directive argument in the range [0, 2147483647]
__builtin_sprintf (buf, "%04d%02d%02d%02d%02d%02d", a, b, c, d, e, f);
^~~~~~~~~~~~~~~~~~~~~~~~~~
u.c:13:27: note: directive argument in the range [0, 2147483647]
u.c:13:3: note: '__builtin_sprintf' output between 15 and 31 bytes into a
destination of size 15
__builtin_sprintf (buf, "%04d%02d%02d%02d%02d%02d", a, b, c, d, e, f);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~