From 0790e74f849e7774649776347ca2b4109290ab6d Mon Sep 17 00:00:00 2001 From: Michael Grant Date: Thu, 22 Jan 2026 14:11:00 +0000 Subject: [PATCH] Fix strftime warning in gcc. --- format.c | 15 +++++++++++++-- window-clock.c | 11 ++++------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/format.c b/format.c index 31fba2a9..332b21c2 100644 --- a/format.c +++ b/format.c @@ -454,6 +454,17 @@ format_job_tidy(struct format_job_tree *jobs, int force) } } +/* Workaround this needless gcc warning: + * warning: format not a string literal, format string not checked [-Wformat-nonliteral] + */ +static size_t +format_strftime(char *s, size_t max, const char *time_format, const struct tm *tm) { +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wformat-nonliteral" + return strftime(s, max, time_format, tm); +#pragma GCC diagnostic pop +} + /* Tidy old jobs for all clients. */ void format_tidy_jobs(void) @@ -3963,7 +3974,7 @@ found: else { if (time_format != NULL) { localtime_r(&t, &tm); - strftime(s, sizeof s, time_format, &tm); + format_strftime(s, sizeof s, time_format, &tm); } else { ctime_r(&t, s); s[strcspn(s, "\n")] = '\0'; @@ -5540,7 +5551,7 @@ format_expand1(struct format_expand_state *es, const char *fmt) es->time = time(NULL); localtime_r(&es->time, &es->tm); } - if (strftime(expanded, sizeof expanded, fmt, &es->tm) == 0) { + if (format_strftime(expanded, sizeof expanded, fmt, &es->tm) == 0) { format_log(es, "format is too long"); return (xstrdup("")); } diff --git a/window-clock.c b/window-clock.c index 81d33858..ecac43ec 100644 --- a/window-clock.c +++ b/window-clock.c @@ -228,7 +228,6 @@ window_clock_draw_screen(struct window_mode_entry *wme) struct screen *s = &data->screen; struct grid_cell gc; char tim[64], *ptr; - const char *timeformat; time_t t; struct tm *tm; u_int i, j, x, y, idx; @@ -242,20 +241,18 @@ window_clock_draw_screen(struct window_mode_entry *wme) tm = localtime(&t); if (style == 0 || style == 2) { if (style == 2) - timeformat = "%l:%M:%S "; + strftime(tim, sizeof tim, "%l:%M:%S ", localtime(&t)); else - timeformat = "%l:%M "; - strftime(tim, sizeof tim, timeformat, localtime(&t)); + strftime(tim, sizeof tim, "%l:%M ", localtime(&t)); if (tm->tm_hour >= 12) strlcat(tim, "PM", sizeof tim); else strlcat(tim, "AM", sizeof tim); } else { if (style == 3) - timeformat = "%H:%M:%S"; + strftime(tim, sizeof tim, "%H:%M:%S", tm); else - timeformat = "%H:%M"; - strftime(tim, sizeof tim, timeformat, tm); + strftime(tim, sizeof tim, "%H:%M", tm); } screen_write_clearscreen(&ctx, 8);