all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Philipp Stephani <p.stephani2@gmail.com>
To: Ken Brown <kbrown@cornell.edu>
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:10:20 +0200	[thread overview]
Message-ID: <CAArVCkTXa6kY3KqwaWGdNV=T7UerxJOV5arB1Foc77JnPUprbQ@mail.gmail.com> (raw)
In-Reply-To: <c8e5c36c-b96b-4df7-aff1-48ff23a84dc0@cornell.edu>

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

Ken Brown <kbrown@cornell.edu> 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.

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

  parent reply	other threads:[~2018-07-19  6:10 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 [this message]
2018-07-19 12:49       ` Ken Brown
2018-07-19 13:25       ` Eli Zaretskii
2018-07-19  6:21   ` Philipp Stephani
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

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

  git send-email \
    --in-reply-to='CAArVCkTXa6kY3KqwaWGdNV=T7UerxJOV5arB1Foc77JnPUprbQ@mail.gmail.com' \
    --to=p.stephani2@gmail.com \
    --cc=32189@debbugs.gnu.org \
    --cc=kbrown@cornell.edu \
    /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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.