unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Philipp Stephani <p.stephani2@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 32189@debbugs.gnu.org
Subject: bug#32189: 27.0.50; GCC 7 warning due to -Wformat-truncation=2
Date: Thu, 19 Jul 2018 08:21:54 +0200	[thread overview]
Message-ID: <CAArVCkRmw4oF3a=UAp1J+CLSoxtdKpx=2KFS032J11nKOzjz+w@mail.gmail.com> (raw)
In-Reply-To: <83601c4m37.fsf@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 1635 bytes --]

Eli Zaretskii <eliz@gnu.org> schrieb am Mi., 18. Juli 2018 um 17:10 Uhr:

> > From: Ken Brown <kbrown@cornell.edu>
> > Date: Tue, 17 Jul 2018 15:26:34 -0400
> >
> > I'm getting the following warning when building the master branch on
> > Cygwin with GCC 7.3:
> >
> > In file included from /usr/include/stdio.h:800:0,
> >                   from ../lib/stdio.h:43,
> >                   from ../../master/src/w32cygwinx.c:22:
> > ../../master/src/w32cygwinx.c: In function ‘Fw32_battery_status’:
> > ../../master/src/w32cygwinx.c:116:26: warning: ‘%3.1f’ directive output
> > may be truncated writing between 3 and 312 bytes into a region of size
> > 16 [-Wformat-truncation=]
> >      snprintf (buffer, 16, "%3.1f", h);
> >                            ^
> > ../../master/src/w32cygwinx.c:116:4: note: ‘__builtin_snprintf’ output
> > between 4 and 313 bytes into a destination of size 16
> >      snprintf (buffer, 16, "%3.1f", h);
> >      ^
>
> Do we really need to use -Wformat-truncation?  Is it a useful warning
> switch?  The above sounds like useless noise, because the code
> explicitly _asks_ for truncation.  What do people think about this?
>

The typical use case for snprintf is to make sure that the output never
gets truncated, so disabling -Wformat-truncation would be harmful in most
cases.
With truncation, the code will result in nonsensical output if the input
value was too large, e.g. 123.4 hours would result in "12" if the buffer
size were 3.
Rather than relying on truncation, the code should probably just use a
buffer that's large enough, or use %g instead of %f.

[-- Attachment #2: Type: text/html, Size: 2164 bytes --]

  parent reply	other threads:[~2018-07-19  6:21 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-17 19:26 bug#32189: 27.0.50; GCC 7 warning due to -Wformat-truncation=2 Ken Brown
2018-07-18 15:09 ` Eli Zaretskii
2018-07-18 19:42   ` Ken Brown
2018-07-19  2:38     ` Eli Zaretskii
2018-07-19  6:10     ` Philipp Stephani
2018-07-19 12:49       ` Ken Brown
2018-07-19 13:25       ` Eli Zaretskii
2018-07-19  6:21   ` Philipp Stephani [this message]
2018-07-19 13:29     ` Eli Zaretskii
2018-07-19 13:56       ` Ken Brown
2018-07-19 14:17         ` Eli Zaretskii
2018-07-19 23:19           ` Paul Eggert
2018-07-20  6:56             ` Eli Zaretskii
2018-07-20 13:49               ` Ken Brown
2018-07-20 14:17                 ` Eli Zaretskii
2018-07-20 14:27                   ` Ken Brown
2018-07-20 14:37                     ` Paul Eggert
2018-07-20 14:51                       ` Eli Zaretskii
2018-07-20 19:34                       ` Ken Brown
2018-07-20 21:03                         ` Paul Eggert

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAArVCkRmw4oF3a=UAp1J+CLSoxtdKpx=2KFS032J11nKOzjz+w@mail.gmail.com' \
    --to=p.stephani2@gmail.com \
    --cc=32189@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).