GNU bug report logs - #32230
27.0.50; GCC 7 warning due to -Wformat-overflow

Previous Next

Package: emacs;

Reported by: Ken Brown <kbrown <at> cornell.edu>

Date: Fri, 20 Jul 2018 22:03:01 UTC

Severity: normal

Found in version 27.0.50

Done: Ken Brown <kbrown <at> cornell.edu>

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 32230 in the body.
You can then email your comments to 32230 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 eggert <at> cs.ucla.edu, bug-gnu-emacs <at> gnu.org:
bug#32230; Package emacs. (Fri, 20 Jul 2018 22:03:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Ken Brown <kbrown <at> cornell.edu>:
New bug report received and forwarded. Copy sent to eggert <at> cs.ucla.edu, bug-gnu-emacs <at> gnu.org. (Fri, 20 Jul 2018 22:03:01 GMT) Full text and rfc822 format available.

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

From: Ken Brown <kbrown <at> cornell.edu>
To: bug-gnu-emacs <at> gnu.org
Subject: 27.0.50; GCC 7 warning due to -Wformat-overflow
Date: Fri, 20 Jul 2018 18:02:07 -0400
The Cygwin-w32 build has turned up another GCC 7 warning:

../../master/src/w32term.c: In function ‘x_draw_glyph_string’:
../../master/src/w32term.c:1477:27: warning: ‘__builtin___sprintf_chk’ 
may write a terminating nul past the end of the destination 
[-Wformat-overflow=]
    sprintf ((char *) buf, "%0*X",
                           ^
../../master/src/w32term.c:1477:4: note: ‘__builtin___sprintf_chk’ 
output between 5 and 8 bytes into a destination of size 7
    sprintf ((char *) buf, "%0*X",
    ^
The method that Paul used in bug#32189 could be used here too, but I'm
not sure it's worth the trouble.  My inclination is to just increase the
buffer size from 7 to 8.

Ken





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#32230; Package emacs. (Sat, 21 Jul 2018 06:54:02 GMT) Full text and rfc822 format available.

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: Ken Brown <kbrown <at> cornell.edu>
Cc: 32230 <at> debbugs.gnu.org, eggert <at> cs.ucla.edu
Subject: Re: bug#32230: 27.0.50; GCC 7 warning due to -Wformat-overflow
Date: Sat, 21 Jul 2018 09:53:04 +0300
> From: Ken Brown <kbrown <at> cornell.edu>
> Date: Fri, 20 Jul 2018 18:02:07 -0400
> Cc: Paul Eggert <eggert <at> cs.ucla.edu>
> 
> The Cygwin-w32 build has turned up another GCC 7 warning:
> 
> ../../master/src/w32term.c: In function ‘x_draw_glyph_string’:
> ../../master/src/w32term.c:1477:27: warning: ‘__builtin___sprintf_chk’ 
> may write a terminating nul past the end of the destination 
> [-Wformat-overflow=]
>      sprintf ((char *) buf, "%0*X",
>                             ^
> ../../master/src/w32term.c:1477:4: note: ‘__builtin___sprintf_chk’ 
> output between 5 and 8 bytes into a destination of size 7
>      sprintf ((char *) buf, "%0*X",
>      ^
> The method that Paul used in bug#32189 could be used here too, but I'm
> not sure it's worth the trouble.  My inclination is to just increase the
> buffer size from 7 to 8.

Yes, with a comment explaining why 8.

But do you understand why it says "between 5 and 8 bytes"?  The
corresponding argument to snprintf is either 4 or 6, so it should be
between 5 and 7.  Where could the extra byte come from?  Is that
because glyphless.ch is a 25-bit field?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#32230; Package emacs. (Sat, 21 Jul 2018 07:27:02 GMT) Full text and rfc822 format available.

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: kbrown <at> cornell.edu
Cc: 32230 <at> debbugs.gnu.org, eggert <at> cs.ucla.edu
Subject: Re: bug#32230: 27.0.50; GCC 7 warning due to -Wformat-overflow
Date: Sat, 21 Jul 2018 10:26:15 +0300
> Date: Sat, 21 Jul 2018 09:53:04 +0300
> From: Eli Zaretskii <eliz <at> gnu.org>
> Cc: 32230 <at> debbugs.gnu.org, eggert <at> cs.ucla.edu
> 
> But do you understand why it says "between 5 and 8 bytes"?  The
> corresponding argument to snprintf is either 4 or 6, so it should be
> between 5 and 7.  Where could the extra byte come from?  Is that
> because glyphless.ch is a 25-bit field?

I meant sprintf, of course.  And if the above is the reason, then
perhaps using something like

  (unsigned int) glyph->u.glyphless.ch & 0xffffff

is a cleaner solution (assuming it shuts up the warning)?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#32230; Package emacs. (Sat, 21 Jul 2018 12:43:01 GMT) Full text and rfc822 format available.

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

From: Ken Brown <kbrown <at> cornell.edu>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 32230 <at> debbugs.gnu.org, eggert <at> cs.ucla.edu
Subject: Re: bug#32230: 27.0.50; GCC 7 warning due to -Wformat-overflow
Date: Sat, 21 Jul 2018 08:42:09 -0400
On 7/21/2018 3:26 AM, Eli Zaretskii wrote:
>> Date: Sat, 21 Jul 2018 09:53:04 +0300
>> From: Eli Zaretskii <eliz <at> gnu.org>
>> Cc: 32230 <at> debbugs.gnu.org, eggert <at> cs.ucla.edu
>>
>> But do you understand why it says "between 5 and 8 bytes"?  The
>> corresponding argument to snprintf is either 4 or 6, so it should be
>> between 5 and 7.  Where could the extra byte come from?  Is that
>> because glyphless.ch is a 25-bit field?

Yes.  Changing the field size to 24 silences the warning.

> I meant sprintf, of course.  And if the above is the reason, then
> perhaps using something like
> 
>    (unsigned int) glyph->u.glyphless.ch & 0xffffff
> 
> is a cleaner solution (assuming it shuts up the warning)?

Yes, it does shut up the warning.  Thanks, I'll make that change.  I 
assume it should go to master, or would you rather have it in the 
emacs-26 branch?

Ken





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#32230; Package emacs. (Sat, 21 Jul 2018 12:48:02 GMT) Full text and rfc822 format available.

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: Ken Brown <kbrown <at> cornell.edu>
Cc: 32230 <at> debbugs.gnu.org, eggert <at> cs.ucla.edu
Subject: Re: bug#32230: 27.0.50; GCC 7 warning due to -Wformat-overflow
Date: Sat, 21 Jul 2018 15:47:43 +0300
> Cc: 32230 <at> debbugs.gnu.org, eggert <at> cs.ucla.edu
> From: Ken Brown <kbrown <at> cornell.edu>
> Date: Sat, 21 Jul 2018 08:42:09 -0400
> 
> > I meant sprintf, of course.  And if the above is the reason, then
> > perhaps using something like
> > 
> >    (unsigned int) glyph->u.glyphless.ch & 0xffffff
> > 
> > is a cleaner solution (assuming it shuts up the warning)?
> 
> Yes, it does shut up the warning.  Thanks, I'll make that change.  I 
> assume it should go to master, or would you rather have it in the 
> emacs-26 branch?

I think it should go to master, thanks.




Reply sent to Ken Brown <kbrown <at> cornell.edu>:
You have taken responsibility. (Sat, 21 Jul 2018 16:27:02 GMT) Full text and rfc822 format available.

Notification sent to Ken Brown <kbrown <at> cornell.edu>:
bug acknowledged by developer. (Sat, 21 Jul 2018 16:27:02 GMT) Full text and rfc822 format available.

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

From: Ken Brown <kbrown <at> cornell.edu>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 32230-done <at> debbugs.gnu.org, eggert <at> cs.ucla.edu
Subject: Re: bug#32230: 27.0.50; GCC 7 warning due to -Wformat-overflow
Date: Sat, 21 Jul 2018 12:26:41 -0400
On 7/21/2018 8:47 AM, Eli Zaretskii wrote:
> I think it should go to master, thanks.

Done, as commit f3f67cf.  But I forgot to reference the bug number in 
the commit message.  I guess there's no way to fix that, except to edit 
ChangeLog.3.  Sorry.

Ken




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#32230; Package emacs. (Sat, 21 Jul 2018 16:41:01 GMT) Full text and rfc822 format available.

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: Ken Brown <kbrown <at> cornell.edu>
Cc: 32230 <at> debbugs.gnu.org, eggert <at> cs.ucla.edu
Subject: Re: bug#32230: 27.0.50; GCC 7 warning due to -Wformat-overflow
Date: Sat, 21 Jul 2018 19:40:08 +0300
> Cc: 32230-done <at> debbugs.gnu.org, eggert <at> cs.ucla.edu
> From: Ken Brown <kbrown <at> cornell.edu>
> Date: Sat, 21 Jul 2018 12:26:41 -0400
> 
> Done, as commit f3f67cf.  But I forgot to reference the bug number in 
> the commit message.

Happens to me as well.

> I guess there's no way to fix that, except to edit ChangeLog.3.
> Sorry.

No sweat.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sun, 19 Aug 2018 11:24:05 GMT) Full text and rfc822 format available.

This bug report was last modified 6 years and 364 days ago.

Previous Next


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