bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#32189: 27.0.50; GCC 7 warning due to -Wformat-truncation=2


From: Philipp Stephani
Subject: bug#32189: 27.0.50; GCC 7 warning due to -Wformat-truncation=2
Date: Thu, 19 Jul 2018 08:10:20 +0200



Ken Brown <address@hidden> schrieb am Mi., 18. Juli 2018 um 21:44 Uhr:


This doesn't work with GCC 7.  (Maybe it would work with GCC 8; the
release notes say that it is better at avoiding false positives.)  For
integer specifiers like "%ld", the only thing I've found that works
without enlarging the buffer is to cast the argument to a smaller
integer type. 

You can't do that; %ld requires a long argument, and casting results in undefined behavior.
 
For float specifiers like "%3.1f", even using a small
type doesn't seem to work.  For example:

$ cat test.c
#include <stdio.h>
int
main ()
{
   char buffer[16];
   short a;
   snprintf (buffer, 16, "%3.1f", a);
}

This is undefined behavior, as %f requires a double argument. 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]