From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Philipp Stephani Newsgroups: gmane.emacs.bugs Subject: bug#32189: 27.0.50; GCC 7 warning due to -Wformat-truncation=2 Date: Thu, 19 Jul 2018 08:10:20 +0200 Message-ID: References: <031d18cf-e661-6dea-8882-38d75924d0d4@cornell.edu> <83601c4m37.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="00000000000062548305715409ad" X-Trace: blaine.gmane.org 1531980553 15315 195.159.176.226 (19 Jul 2018 06:09:13 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 19 Jul 2018 06:09:13 +0000 (UTC) Cc: 32189@debbugs.gnu.org To: Ken Brown Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Jul 19 08:09:09 2018 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fg27d-0003q7-DR for geb-bug-gnu-emacs@m.gmane.org; Thu, 19 Jul 2018 08:09:05 +0200 Original-Received: from localhost ([::1]:39935 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fg29i-0007o8-QI for geb-bug-gnu-emacs@m.gmane.org; Thu, 19 Jul 2018 02:11:14 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:36654) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fg29a-0007o1-95 for bug-gnu-emacs@gnu.org; Thu, 19 Jul 2018 02:11:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fg29W-0003R1-1s for bug-gnu-emacs@gnu.org; Thu, 19 Jul 2018 02:11:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:42423) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fg29V-0003Qa-Ud for bug-gnu-emacs@gnu.org; Thu, 19 Jul 2018 02:11:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1fg29V-00031Z-JO for bug-gnu-emacs@gnu.org; Thu, 19 Jul 2018 02:11:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Philipp Stephani Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 19 Jul 2018 06:11:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 32189 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 32189-submit@debbugs.gnu.org id=B32189.153198064011596 (code B ref 32189); Thu, 19 Jul 2018 06:11:01 +0000 Original-Received: (at 32189) by debbugs.gnu.org; 19 Jul 2018 06:10:40 +0000 Original-Received: from localhost ([127.0.0.1]:47440 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fg29A-00030y-2Y for submit@debbugs.gnu.org; Thu, 19 Jul 2018 02:10:40 -0400 Original-Received: from mail-oi0-f43.google.com ([209.85.218.43]:37711) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fg298-00030i-0r for 32189@debbugs.gnu.org; Thu, 19 Jul 2018 02:10:38 -0400 Original-Received: by mail-oi0-f43.google.com with SMTP id k81-v6so13398325oib.4 for <32189@debbugs.gnu.org>; Wed, 18 Jul 2018 23:10:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=d6dOBxpZYU567aK6PijFyp4FD3lylBWv96cWHPh0BBc=; b=cwN+Jjlo932L0RtZky4w8ma+1ibqtxaELaHlCVNIkmJQYCISDkdPBywVm1Qx7hF1I8 9pyMrXk4/bZRi1k+ID81HwylwkHIKAgTy4q4pAElxW7gT6Iagmcq49++zxYTqvTxhA95 A1dCjyhOx/U9Dyu5tlM291WZYUHHbNrtnJL092wL6rBdGc8EAxZGaunYi65T3DPOE/s3 Fowuc515THYl0Kdiu9JIpc23dADwXbuWRa7IdQhaFlbaSH8h/s24zBgqNT1pttyaXojZ auWNcfrL+/StEvdEWr23CexoFrWP4v9F5IlrV1/UXeO00+gE/8Eny3+v/MQlFkoqh89g wlag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=d6dOBxpZYU567aK6PijFyp4FD3lylBWv96cWHPh0BBc=; b=rMsKewG0cOTFZybPUNMqVysCQe6YbTBfHE8lk5uLqJjhOM/jdbD1KJjBD1yRwSRqcn gGyhe3TsL4yb2TVmWwWzES39AWsESxkoi7ub808Tde8ObPy7m+MaP6u9ShgOgdB0l+FL Uh5WgrheF5jwJNwvYImqOg4Xo1pTZko+yPM+DKV25IsskTbGcKeCrRFvjEaQJhivGAAM oalk4J5XmQKd9JDzGIwp2WGqeX+cY0TOoE+mx2D4IVtz3eB+FxJmKrQzzTnhjE94M9NJ Ve9Fub7+XpJXxInQMkYOERcKKQUo9dhgVU1/Xj8rAB7FKn7/tAeu3OiwrmVqlBDiOZ4E vagQ== X-Gm-Message-State: AOUpUlExdvU895VMULUUC1kIN59XSuopeKCfjEkQOAR6EqnwXRBZGfwW NflMDThp9A2xh7JZD6ngpcAPnLBsRdlWx//2ndw= X-Google-Smtp-Source: AAOMgpdydKkbVHzGTtFGmGoUohs5YmoSfMvvNTOuiKMy4cGKIVGnXW2lvcbygSXsYpX0cttRhOOG/HDW5VvR/WgMkVY= X-Received: by 2002:aca:4914:: with SMTP id w20-v6mr8935862oia.5.1531980632182; Wed, 18 Jul 2018 23:10:32 -0700 (PDT) In-Reply-To: X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:148659 Archived-At: --00000000000062548305715409ad Content-Type: text/plain; charset="UTF-8" Ken Brown 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 > int > main () > { > char buffer[16]; > short a; > snprintf (buffer, 16, "%3.1f", a); > } > This is undefined behavior, as %f requires a double argument. --00000000000062548305715409ad Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


Ken Br= own <kbrown@cornell.edu> sc= hrieb am Mi., 18. Juli 2018 um 21:44=C2=A0Uhr:


This doesn't work with GCC 7.=C2=A0 (Maybe it would work with GCC 8; th= e
release notes say that it is better at avoiding false positives.)=C2=A0 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.=C2=A0

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

$ cat test.c
#include <stdio.h>
int
main ()
{
=C2=A0 =C2=A0char buffer[16];
=C2=A0 =C2=A0short a;
=C2=A0 =C2=A0snprintf (buffer, 16, "%3.1f", a);
}

This is undefined behavior, as %f requires= a double argument.=C2=A0
--00000000000062548305715409ad--