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:21:54 +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="000000000000be13d60571543214" X-Trace: blaine.gmane.org 1531981267 29421 195.159.176.226 (19 Jul 2018 06:21:07 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 19 Jul 2018 06:21:07 +0000 (UTC) Cc: 32189@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Jul 19 08:21:03 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 1fg2JC-0007Za-DW for geb-bug-gnu-emacs@m.gmane.org; Thu, 19 Jul 2018 08:21:02 +0200 Original-Received: from localhost ([::1]:39957 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fg2LJ-00010G-E6 for geb-bug-gnu-emacs@m.gmane.org; Thu, 19 Jul 2018 02:23:13 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:38147) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fg2LC-000106-Qu for bug-gnu-emacs@gnu.org; Thu, 19 Jul 2018 02:23:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fg2L8-0007wn-PT for bug-gnu-emacs@gnu.org; Thu, 19 Jul 2018 02:23:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:42427) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fg2L8-0007wi-Lh for bug-gnu-emacs@gnu.org; Thu, 19 Jul 2018 02:23:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1fg2L8-0005HS-DQ for bug-gnu-emacs@gnu.org; Thu, 19 Jul 2018 02:23:02 -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:23:02 +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.153198133620226 (code B ref 32189); Thu, 19 Jul 2018 06:23:02 +0000 Original-Received: (at 32189) by debbugs.gnu.org; 19 Jul 2018 06:22:16 +0000 Original-Received: from localhost ([127.0.0.1]:47445 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fg2KM-0005G8-6g for submit@debbugs.gnu.org; Thu, 19 Jul 2018 02:22:14 -0400 Original-Received: from mail-oi0-f46.google.com ([209.85.218.46]:44309) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fg2KJ-0005Fv-M9 for 32189@debbugs.gnu.org; Thu, 19 Jul 2018 02:22:12 -0400 Original-Received: by mail-oi0-f46.google.com with SMTP id s198-v6so13417166oih.11 for <32189@debbugs.gnu.org>; Wed, 18 Jul 2018 23:22:11 -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=QbW1aGg1Yg6C6sjf/TJtRQgKL9xCb9YDZg/ev8sXByA=; b=gLeDqfIWTxtQf/uk8wdhrFadH49TK+rKERhnXcGWy3QCtoa9hMDvtwve4TTNndNv5O c63m7y7ttJ5OJe5iS2ccqykqs2R08W2e9nKrfJquhRYyQUyYrtebhfcI1zA2Ro770IcH kpoYu0wvu6jWHBdA8hqQ2Wy7+DIfp3wBuz6kJ5mtdVuC/pJlFhgAIi4JA4iE3CpdIECL t61thqFzxeCMkQuSFbPshjGcHgS13eDipiet5O8mk/SKdk6W17F5ChqpebzzdhpgwgMi wHo1h6tL+J6gq3NWuDdemBQPp+jGZW3IDujdGuNJAS9XdHF777K4C6hwheIpgGbGbwRJ 3uHg== 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=QbW1aGg1Yg6C6sjf/TJtRQgKL9xCb9YDZg/ev8sXByA=; b=RfERp/8NMCn4EWfm7ZvkR7BIXklcmIi18IMakUHKQM3e8kHbXgdTYoWsYB6Yv/0pQs eo5RyjNvwtr5oFdh9okmicsKcxfxmTD25SpkxC054UMKupdUENCytcQ7w/Rz31kAOeEz QqM+ZOiQgm1BOtBkU1kvzTwM6+gKgwxIMQnnv6KcHQqyhYiHkI5RbQWxP2Tp7qt17vJE E3sZNdSXKO0sh4DzLfk5OshvJCkcBXJVAnbkXbTPGgIw8iVsGN6zNMl+TloW93KADF7R adNGUSegrJYau9h5eJwOoTn+DMUv+2tPmYIqo5KzIi+OgA8WDlqdx0fixFeOjVwk800L +svQ== X-Gm-Message-State: AOUpUlFpgSyb0kSnV0z0rgHyfoDIQBtK6dncXsY6MP9G0eMz1Za3pZvL s4tbRRoL+g/EXo3qDE/Ya2u1H6H/FUQ99SbIwgg= X-Google-Smtp-Source: AAOMgpdFnmdtm2z7jrvKTL76sX2p7VXMkU7BS0d8azBQZxE6Ygs8IBrIFSLc4gAvk7Ax1gzzJPyAu59etDuROJYmcIM= X-Received: by 2002:aca:3f55:: with SMTP id m82-v6mr10017033oia.237.1531981326060; Wed, 18 Jul 2018 23:22:06 -0700 (PDT) In-Reply-To: <83601c4m37.fsf@gnu.org> 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:148660 Archived-At: --000000000000be13d60571543214 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Eli Zaretskii schrieb am Mi., 18. Juli 2018 um 17:10 Uhr: > > From: Ken Brown > > 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 =E2=80=98Fw32_battery_status= =E2=80=99: > > ../../master/src/w32cygwinx.c:116:26: warning: =E2=80=98%3.1f=E2=80=99 = directive output > > may be truncated writing between 3 and 312 bytes into a region of size > > 16 [-Wformat-truncation=3D] > > snprintf (buffer, 16, "%3.1f", h); > > ^ > > ../../master/src/w32cygwinx.c:116:4: note: =E2=80=98__builtin_snprintf= =E2=80=99 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. --000000000000be13d60571543214 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


Eli Za= retskii <eliz@gnu.org> schrieb am= Mi., 18. Juli 2018 um 17:10=C2=A0Uhr:
> 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,
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0fr= om ../lib/stdio.h:43,
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0fr= om ../../master/src/w32cygwinx.c:22:
> ../../master/src/w32cygwinx.c: In function =E2=80=98Fw32_battery_statu= s=E2=80=99:
> ../../master/src/w32cygwinx.c:116:26: warning: =E2=80=98%3.1f=E2=80=99= directive output
> may be truncated writing between 3 and 312 bytes into a region of size=
> 16 [-Wformat-truncation=3D]
>=C2=A0 =C2=A0 =C2=A0 snprintf (buffer, 16, "%3.1f", h);
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 ^
> ../../master/src/w32cygwinx.c:116:4: note: =E2=80=98__builtin_snprintf= =E2=80=99 output
> between 4 and 313 bytes into a destination of size 16
>=C2=A0 =C2=A0 =C2=A0 snprintf (buffer, 16, "%3.1f", h);
>=C2=A0 =C2=A0 =C2=A0 ^

Do we really need to use -Wformat-truncation?=C2=A0 Is it a useful warning<= br> switch?=C2=A0 The above sounds like useless noise, because the code
explicitly _asks_ for truncation.=C2=A0 What do people think about this?

The typical use case for snprintf is to ma= ke sure that the output never gets truncated, so disabling -Wformat-truncat= ion would be harmful in most cases.
With truncation, the code wil= l 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 buff= er that's large enough, or use %g instead of %f.=C2=A0
--000000000000be13d60571543214--