From 99a79b595f95829cb3e70bee2dbbed3a122127af Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Wed, 24 Sep 2025 16:20:50 +0200 Subject: [PATCH] eve/stats: work around format truncation warnings This appears to be a FP. Work around it to allow for using this warning as an error. output-json-stats.c: In function 'StatsToJSON': output-json-stats.c:253:65: warning: 'snprintf' output may be truncated before the last format character [-Wformat-truncation=] 253 | snprintf(deltaname, sizeof(deltaname), "%s%s", stat_name, delta_suffix); | ^ output-json-stats.c:253:21: note: 'snprintf' output 1 or more bytes (assuming 8) into a destination of size 7 253 | snprintf(deltaname, sizeof(deltaname), "%s%s", stat_name, delta_suffix); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ output-json-stats.c:314:69: warning: 'snprintf' output may be truncated before the last format character [-Wformat-truncation=] 314 | snprintf(deltaname, sizeof(deltaname), "%s%s", stat_name, delta_suffix); | ^ output-json-stats.c:314:25: note: 'snprintf' output 1 or more bytes (assuming 8) into a destination of size 7 314 | snprintf(deltaname, sizeof(deltaname), "%s%s", stat_name, delta_suffix); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Ticket: #7905. --- src/output-json-stats.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/output-json-stats.c b/src/output-json-stats.c index bdcaa10d48..7b07500e6a 100644 --- a/src/output-json-stats.c +++ b/src/output-json-stats.c @@ -249,7 +249,8 @@ json_t *StatsToJSON(const StatsTable *st, uint8_t flags) json_object_set_new(js_type, stat_name, json_integer(st->stats[u].value)); if (flags & JSON_STATS_DELTAS) { - char deltaname[strlen(stat_name) + strlen(delta_suffix) + 1]; + /* add +1 to safisfy gcc 15 + -Wformat-truncation=2 */ + char deltaname[strlen(stat_name) + strlen(delta_suffix) + 2]; snprintf(deltaname, sizeof(deltaname), "%s%s", stat_name, delta_suffix); json_object_set_new(js_type, deltaname, json_integer(st->stats[u].value - st->stats[u].pvalue)); @@ -310,7 +311,7 @@ json_t *StatsToJSON(const StatsTable *st, uint8_t flags) json_object_set_new(js_type, stat_name, json_integer(st->tstats[u].value)); if (flags & JSON_STATS_DELTAS) { - char deltaname[strlen(stat_name) + strlen(delta_suffix) + 1]; + char deltaname[strlen(stat_name) + strlen(delta_suffix) + 2]; snprintf(deltaname, sizeof(deltaname), "%s%s", stat_name, delta_suffix); json_object_set_new(js_type, deltaname, json_integer(st->tstats[u].value - st->tstats[u].pvalue));