unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#32189: 27.0.50; GCC 7 warning due to -Wformat-truncation=2
@ 2018-07-17 19:26 Ken Brown
  2018-07-18 15:09 ` Eli Zaretskii
  0 siblings, 1 reply; 20+ messages in thread
From: Ken Brown @ 2018-07-17 19:26 UTC (permalink / raw)
  To: 32189

[-- Attachment #1: Type: text/plain, Size: 1100 bytes --]

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 ‘Fw32_battery_status’:
../../master/src/w32cygwinx.c:116:26: warning: ‘%3.1f’ directive output 
may be truncated writing between 3 and 312 bytes into a region of size 
16 [-Wformat-truncation=]
     snprintf (buffer, 16, "%3.1f", h);
                           ^
../../master/src/w32cygwinx.c:116:4: note: ‘__builtin_snprintf’ output 
between 4 and 313 bytes into a destination of size 16
     snprintf (buffer, 16, "%3.1f", h);
     ^

The attached patch avoids the warning.  Is this a reasonable fix, or is
there a better way?


In GNU Emacs 27.0.50 (build 6, x86_64-unknown-cygwin, GTK+ Version 3.22.28)
  of 2018-07-17 built on moufang
Repository revision: 04599bb1b219b236356ba3393a23e1c1dd8c541b
Windowing system distributor 'The Cygwin/X Project', version 11.0.12000000


[-- Attachment #2: 0001-Pacify-GCC-7-with-Wformat-truncation-2.patch --]
[-- Type: text/plain, Size: 1231 bytes --]

From f79ad94f8dcca82aa1523ef89ff88aab1b2d3fe4 Mon Sep 17 00:00:00 2001
From: Ken Brown <kbrown@cornell.edu>
Date: Tue, 17 Jul 2018 15:12:35 -0400
Subject: [PATCH] Pacify GCC 7 with -Wformat-truncation=2

* src/w32cygwinx.c (Fw32_battery_status): Increase size of
'buffer'.  (Bug#xxxxx)
---
 src/w32cygwinx.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/w32cygwinx.c b/src/w32cygwinx.c
index 8d3ae164cf..f7bbf17a16 100644
--- a/src/w32cygwinx.c
+++ b/src/w32cygwinx.c
@@ -104,19 +104,19 @@ The following %-sequences are provided:
 	{
 	  long m;
 	  double h;
-	  char buffer[16];
-	  snprintf (buffer, 16, "%ld", seconds_left);
+	  char buffer[400];
+	  snprintf (buffer, 400, "%ld", seconds_left);
 	  seconds = build_string (buffer);
 
 	  m = seconds_left / 60;
-	  snprintf (buffer, 16, "%ld", m);
+	  snprintf (buffer, 400, "%ld", m);
 	  minutes = build_string (buffer);
 
 	  h = seconds_left / 3600.0;
-	  snprintf (buffer, 16, "%3.1f", h);
+	  snprintf (buffer, 400, "%3.1f", h);
 	  hours = build_string (buffer);
 
-	  snprintf (buffer, 16, "%ld:%02ld", m / 60, m % 60);
+	  snprintf (buffer, 400, "%ld:%02ld", m / 60, m % 60);
 	  remain = build_string (buffer);
 	}
 
-- 
2.17.0


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

end of thread, other threads:[~2018-07-20 21:03 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-07-17 19:26 bug#32189: 27.0.50; GCC 7 warning due to -Wformat-truncation=2 Ken Brown
2018-07-18 15:09 ` Eli Zaretskii
2018-07-18 19:42   ` Ken Brown
2018-07-19  2:38     ` Eli Zaretskii
2018-07-19  6:10     ` Philipp Stephani
2018-07-19 12:49       ` Ken Brown
2018-07-19 13:25       ` Eli Zaretskii
2018-07-19  6:21   ` Philipp Stephani
2018-07-19 13:29     ` Eli Zaretskii
2018-07-19 13:56       ` Ken Brown
2018-07-19 14:17         ` Eli Zaretskii
2018-07-19 23:19           ` Paul Eggert
2018-07-20  6:56             ` Eli Zaretskii
2018-07-20 13:49               ` Ken Brown
2018-07-20 14:17                 ` Eli Zaretskii
2018-07-20 14:27                   ` Ken Brown
2018-07-20 14:37                     ` Paul Eggert
2018-07-20 14:51                       ` Eli Zaretskii
2018-07-20 19:34                       ` Ken Brown
2018-07-20 21:03                         ` Paul Eggert

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