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.
pull/13926/head
Victor Julien 2 months ago committed by Victor Julien
parent a57643c70b
commit 99a79b595f

@ -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));

Loading…
Cancel
Save