unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#42656: term.c:1405:25: warning: ‘%d’ directive writing between 2 and 10 bytes into a region of size 3
@ 2020-08-01 19:27 Jeffrey Walton
  2020-08-01 19:43 ` Andreas Schwab
  2020-08-17 23:36 ` Paul Eggert
  0 siblings, 2 replies; 8+ messages in thread
From: Jeffrey Walton @ 2020-08-01 19:27 UTC (permalink / raw)
  To: 42656

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,





^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#42656: term.c:1405:25: warning: ‘%d’ directive writing between 2 and 10 bytes into a region of size 3
  2020-08-01 19:27 bug#42656: term.c:1405:25: warning: ‘%d’ directive writing between 2 and 10 bytes into a region of size 3 Jeffrey Walton
@ 2020-08-01 19:43 ` Andreas Schwab
  2020-08-09 23:07   ` Lars Ingebrigtsen
  2020-08-28  6:06   ` Jeffrey Walton
  2020-08-17 23:36 ` Paul Eggert
  1 sibling, 2 replies; 8+ messages in thread
From: Andreas Schwab @ 2020-08-01 19:43 UTC (permalink / raw)
  To: Jeffrey Walton; +Cc: 42656

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@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."





^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#42656: term.c:1405:25: warning: ‘%d’ directive writing between 2 and 10 bytes into a region of size 3
  2020-08-01 19:43 ` Andreas Schwab
@ 2020-08-09 23:07   ` Lars Ingebrigtsen
  2020-08-28  6:06   ` Jeffrey Walton
  1 sibling, 0 replies; 8+ messages in thread
From: Lars Ingebrigtsen @ 2020-08-09 23:07 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: Jeffrey Walton, 42656

Andreas Schwab <schwab@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





^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#42656: term.c:1405:25: warning: ‘%d’ directive writing between 2 and 10 bytes into a region of size 3
  2020-08-01 19:27 bug#42656: term.c:1405:25: warning: ‘%d’ directive writing between 2 and 10 bytes into a region of size 3 Jeffrey Walton
  2020-08-01 19:43 ` Andreas Schwab
@ 2020-08-17 23:36 ` Paul Eggert
  2020-08-18  9:44   ` Andy Moreton
  2020-08-25 13:38   ` Stefan Kangas
  1 sibling, 2 replies; 8+ messages in thread
From: Paul Eggert @ 2020-08-17 23:36 UTC (permalink / raw)
  To: Jeffrey Walton; +Cc: 42656

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).





^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#42656: term.c:1405:25: warning: ‘%d’ directive writing between 2 and 10 bytes into a region of size 3
  2020-08-17 23:36 ` Paul Eggert
@ 2020-08-18  9:44   ` Andy Moreton
  2020-08-25 13:38   ` Stefan Kangas
  1 sibling, 0 replies; 8+ messages in thread
From: Andy Moreton @ 2020-08-18  9:44 UTC (permalink / raw)
  To: 42656

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






^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#42656: term.c:1405:25: warning: ‘%d’ directive writing between 2 and 10 bytes into a region of size 3
  2020-08-17 23:36 ` Paul Eggert
  2020-08-18  9:44   ` Andy Moreton
@ 2020-08-25 13:38   ` Stefan Kangas
  1 sibling, 0 replies; 8+ messages in thread
From: Stefan Kangas @ 2020-08-25 13:38 UTC (permalink / raw)
  To: Paul Eggert; +Cc: Jeffrey Walton, 42656-done

Paul Eggert <eggert@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.





^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#42656: term.c:1405:25: warning: ‘%d’ directive writing between 2 and 10 bytes into a region of size 3
  2020-08-01 19:43 ` Andreas Schwab
  2020-08-09 23:07   ` Lars Ingebrigtsen
@ 2020-08-28  6:06   ` Jeffrey Walton
  2020-08-28  7:27     ` Andreas Schwab
  1 sibling, 1 reply; 8+ messages in thread
From: Jeffrey Walton @ 2020-08-28  6:06 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: 42656

On Sat, Aug 1, 2020 at 3:43 PM Andreas Schwab <schwab@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





^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#42656: term.c:1405:25: warning: ‘%d’ directive writing between 2 and 10 bytes into a region of size 3
  2020-08-28  6:06   ` Jeffrey Walton
@ 2020-08-28  7:27     ` Andreas Schwab
  0 siblings, 0 replies; 8+ messages in thread
From: Andreas Schwab @ 2020-08-28  7:27 UTC (permalink / raw)
  To: Jeffrey Walton; +Cc: 42656

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@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."





^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2020-08-28  7:27 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-08-01 19:27 bug#42656: term.c:1405:25: warning: ‘%d’ directive writing between 2 and 10 bytes into a region of size 3 Jeffrey Walton
2020-08-01 19:43 ` Andreas Schwab
2020-08-09 23:07   ` Lars Ingebrigtsen
2020-08-28  6:06   ` Jeffrey Walton
2020-08-28  7:27     ` Andreas Schwab
2020-08-17 23:36 ` Paul Eggert
2020-08-18  9:44   ` Andy Moreton
2020-08-25 13:38   ` Stefan Kangas

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).