GNU bug report logs - #42656
term.c:1405:25: warning: ‘%d’ directive writing between 2 and 10 bytes into a region of size 3

Previous Next

Package: emacs;

Reported by: noloader <at> gmail.com

Date: Sat, 1 Aug 2020 19:29:02 UTC

Severity: normal

Tags: notabug

Done: Stefan Kangas <stefan <at> marxist.se>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 42656 in the body.
You can then email your comments to 42656 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#42656; Package emacs. (Sat, 01 Aug 2020 19:29:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to noloader <at> gmail.com:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sat, 01 Aug 2020 19:29:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Jeffrey Walton <noloader <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: term.c:1405:25: warning: ‘%d’ directive writing between 2 and 10 bytes into a region of size 3
Date: Sat, 1 Aug 2020 15:27:48 -0400
I think this can be cleared by clamping the argument.

term.c: In function ‘term_get_fkeys_1’:
term.c:1405:25: warning: ‘%d’ directive writing between 2 and 10 bytes
into a region of size 3 [-Wformat-overflow=]
        sprintf (fkey, "f%d", i);
                         ^~
term.c:1405:23: note: directive argument in the range [11, 2147483646]
        sprintf (fkey, "f%d", i);
                       ^~~~~
In file included from /usr/include/stdio.h:862:0,
                 from ../lib/stdio.h:43,
                 from termchar.h:22,
                 from term.c:31:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:33:10: note:
‘__builtin___sprintf_chk’ output between 4 and 12 bytes into a
destination of size 4
   return __builtin___sprintf_chk (__s, __USE_FORTIFY_LEVEL - 1,




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#42656; Package emacs. (Sat, 01 Aug 2020 19:44:02 GMT) Full text and rfc822 format available.

Message #8 received at 42656 <at> debbugs.gnu.org (full text, mbox):

From: Andreas Schwab <schwab <at> linux-m68k.org>
To: Jeffrey Walton <noloader <at> gmail.com>
Cc: 42656 <at> debbugs.gnu.org
Subject: Re: bug#42656: term.c:1405:25: warning: ‘%d’
 directive writing between 2 and 10 bytes into a region of size 3
Date: Sat, 01 Aug 2020 21:43:20 +0200
On Aug 01 2020, Jeffrey Walton wrote:

> term.c:1405:23: note: directive argument in the range [11, 2147483646]
>         sprintf (fkey, "f%d", i);
>                        ^~~~~

That's clearly a compiler bug.  The loop counts i from 11 to 64, so
2147483646 can never happen.

Andreas.

-- 
Andreas Schwab, schwab <at> linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#42656; Package emacs. (Sun, 09 Aug 2020 23:08:02 GMT) Full text and rfc822 format available.

Message #11 received at 42656 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Andreas Schwab <schwab <at> linux-m68k.org>
Cc: Jeffrey Walton <noloader <at> gmail.com>, 42656 <at> debbugs.gnu.org
Subject: Re: bug#42656: term.c:1405:25: warning: ‘%d’
 directive writing between 2 and 10 bytes into a region of size 3
Date: Mon, 10 Aug 2020 01:07:11 +0200
Andreas Schwab <schwab <at> linux-m68k.org> writes:

> On Aug 01 2020, Jeffrey Walton wrote:
>
>> term.c:1405:23: note: directive argument in the range [11, 2147483646]
>>         sprintf (fkey, "f%d", i);
>>                        ^~~~~
>
> That's clearly a compiler bug.  The loop counts i from 11 to 64, so
> 2147483646 can never happen.

Yeah, that clearly seems like a compiler bug?  What compiler are you
using?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Added tag(s) notabug. Request was from Stefan Kangas <stefan <at> marxist.se> to control <at> debbugs.gnu.org. (Thu, 13 Aug 2020 00:02:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#42656; Package emacs. (Mon, 17 Aug 2020 23:37:02 GMT) Full text and rfc822 format available.

Message #16 received at 42656 <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Jeffrey Walton <noloader <at> gmail.com>
Cc: 42656 <at> debbugs.gnu.org
Subject: term.c:1405:25: warning: ‘%d’ directive writing between 2 and 10 bytes into a region of size 3
Date: Mon, 17 Aug 2020 16:36:16 -0700
I regularly get messages like that from old versions of GCC. It's better to 
ignore such messages, as we shouldn't clutter up the code merely to pacify older 
(or buggy) compilers.

You can build with --disable-gcc-warnings to suppress the annoyances with older 
compilers (if you're building from Git, that is; you shouldn't need to specify 
anything if building from a tarball).




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#42656; Package emacs. (Tue, 18 Aug 2020 09:45:01 GMT) Full text and rfc822 format available.

Message #19 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Andy Moreton <andrewjmoreton <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: Re: bug#42656: term.c:1405:25: warning: ‘%d’
 directive writing between 2 and 10 bytes into a region of size 3
Date: Tue, 18 Aug 2020 10:44:24 +0100
On Mon 17 Aug 2020, Paul Eggert wrote:

> I regularly get messages like that from old versions of GCC. It's better to
> ignore such messages, as we shouldn't clutter up the code merely to pacify
> older (or buggy) compilers.
>
> You can build with --disable-gcc-warnings to suppress the annoyances with
> older compilers (if you're building from Git, that is; you shouldn't need to
> specify anything if building from a tarball).

If the warning regularly generates many false positive results, then
disabling the warning should be be done by default, so an unmodified
tree gives a clean build.

    AndyM





Reply sent to Stefan Kangas <stefan <at> marxist.se>:
You have taken responsibility. (Tue, 25 Aug 2020 13:39:04 GMT) Full text and rfc822 format available.

Notification sent to noloader <at> gmail.com:
bug acknowledged by developer. (Tue, 25 Aug 2020 13:39:04 GMT) Full text and rfc822 format available.

Message #24 received at 42656-done <at> debbugs.gnu.org (full text, mbox):

From: Stefan Kangas <stefan <at> marxist.se>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: Jeffrey Walton <noloader <at> gmail.com>, 42656-done <at> debbugs.gnu.org
Subject: Re: bug#42656: term.c:1405:25: warning: ‘%d’ directive writing between 2 and 10 bytes into a region of size 3
Date: Tue, 25 Aug 2020 06:38:43 -0700
Paul Eggert <eggert <at> cs.ucla.edu> writes:

> I regularly get messages like that from old versions of GCC. It's better to
> ignore such messages, as we shouldn't clutter up the code merely to pacify older
> (or buggy) compilers.
>
> You can build with --disable-gcc-warnings to suppress the annoyances with older
> compilers (if you're building from Git, that is; you shouldn't need to specify
> anything if building from a tarball).

I think the consensus here is that this is a compiler bug that should be
ignored.  I'm therefore closing this bug report.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#42656; Package emacs. (Fri, 28 Aug 2020 06:08:02 GMT) Full text and rfc822 format available.

Message #27 received at 42656 <at> debbugs.gnu.org (full text, mbox):

From: Jeffrey Walton <noloader <at> gmail.com>
To: Andreas Schwab <schwab <at> linux-m68k.org>
Cc: 42656 <at> debbugs.gnu.org
Subject: Re: bug#42656: term.c:1405:25: warning: ‘%d’ directive writing between 2 and 10 bytes into a region of size 3
Date: Fri, 28 Aug 2020 02:06:45 -0400
On Sat, Aug 1, 2020 at 3:43 PM Andreas Schwab <schwab <at> linux-m68k.org> wrote:
>
> On Aug 01 2020, Jeffrey Walton wrote:
>
> > term.c:1405:23: note: directive argument in the range [11, 2147483646]
> >         sprintf (fkey, "f%d", i);
> >                        ^~~~~
>
> That's clearly a compiler bug.  The loop counts i from 11 to 64, so
> 2147483646 can never happen.

Sorry for the late reply.

What I have found is, analysis is catching the case where printf
family returns -1. It is non-obvious, and I think it's a case where a
better message should be supplied.

The best way I have found to handle it is to terminate the string on
failure. This seems to squash the warning in the cases I have
encountered.

  #define TERM_PRINTF(buf, len, rc) \
      buf[rc < 0 ? 0 : rc >= len ? len-1 : rc] = '\0'

  int rc = snprintf(buf, sizeof(buf), "%d", n);
  TERM_PRINTF(buf, sizeof(buf), rc);

I don't know if it will help in this case since I did not perform the
patch. But it is the first thing I would try if I was working the bug.

Jeff




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#42656; Package emacs. (Fri, 28 Aug 2020 07:28:01 GMT) Full text and rfc822 format available.

Message #30 received at 42656 <at> debbugs.gnu.org (full text, mbox):

From: Andreas Schwab <schwab <at> linux-m68k.org>
To: Jeffrey Walton <noloader <at> gmail.com>
Cc: 42656 <at> debbugs.gnu.org
Subject: Re: bug#42656: term.c:1405:25: warning: ‘%d’
 directive writing between 2 and 10 bytes into a region of size 3
Date: Fri, 28 Aug 2020 09:27:29 +0200
On Aug 28 2020, Jeffrey Walton wrote:

> What I have found is, analysis is catching the case where printf
> family returns -1.

Which printf?  And what does that have to do with the value of i?

Andreas.

-- 
Andreas Schwab, schwab <at> linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Fri, 25 Sep 2020 11:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 3 years and 214 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.