From: Paul Eggert Date: Thu, 19 Jul 2018 23:12:17 +0000 (-0700) Subject: Simplify w32cygwinx.c and pacify GCC (Bug#32189) X-Git-Tag: emacs-27.0.90~4664^2~55 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=144bcc0132e61cc932348312720d592764022844;p=emacs.git Simplify w32cygwinx.c and pacify GCC (Bug#32189) * src/w32cygwinx.c (format_string): New function. (Fw32_battery_status): Use it. --- diff --git a/src/w32cygwinx.c b/src/w32cygwinx.c index 8d3ae164cf6..5d48c3a9e1e 100644 --- a/src/w32cygwinx.c +++ b/src/w32cygwinx.c @@ -24,6 +24,16 @@ along with GNU Emacs. If not, see . */ #include "lisp.h" #include "w32common.h" +static Lisp_Object ATTRIBUTE_FORMAT_PRINTF (1, 2) +format_string (char const *format, ...) +{ + va_list args; + va_start (args, format); + Lisp_Object str = vformat_string (format, args); + va_end (args); + return str; +} + DEFUN ("w32-battery-status", Fw32_battery_status, Sw32_battery_status, 0, 0, 0, doc: /* Get power status information from Windows system. @@ -92,32 +102,17 @@ The following %-sequences are provided: if (system_status.BatteryLifePercent > 100) load_percentage = build_string ("N/A"); else - { - char buffer[16]; - snprintf (buffer, 16, "%d", system_status.BatteryLifePercent); - load_percentage = build_string (buffer); - } + load_percentage = format_string ("%d", system_status.BatteryLifePercent); if (seconds_left < 0) seconds = minutes = hours = remain = build_string ("N/A"); else { - long m; - double h; - char buffer[16]; - snprintf (buffer, 16, "%ld", seconds_left); - seconds = build_string (buffer); - - m = seconds_left / 60; - snprintf (buffer, 16, "%ld", m); - minutes = build_string (buffer); - - h = seconds_left / 3600.0; - snprintf (buffer, 16, "%3.1f", h); - hours = build_string (buffer); - - snprintf (buffer, 16, "%ld:%02ld", m / 60, m % 60); - remain = build_string (buffer); + long m = seconds_left / 60; + seconds = format_string ("%ld", seconds_left); + minutes = format_string ("%ld", m); + hours = format_string ("%3.1f", seconds_left / 3600.0); + remain = format_string ("%ld:%02ld", m / 60, m % 60); } status = listn (CONSTYPE_HEAP, 8,