eve/alert: work around format truncation warning

This appears to be a FP. Work around it to allow for using this warning
as an error.

output-json-alert.c: In function 'AlertJsonReference':
output-json-alert.c:188:44: warning: '%s' directive output may be truncated writing likely 1 or more bytes into a region of size between 0 and 1 [-Wformat-truncation=]
  188 |         snprintf(kv_store, size_needed, "%s%s", kv->key, kv->reference);
      |                                            ^~
output-json-alert.c:188:41: note: assuming directive output of 1 byte
  188 |         snprintf(kv_store, size_needed, "%s%s", kv->key, kv->reference);
      |                                         ^~~~~~
output-json-alert.c:188:9: note: 'snprintf' output 1 or more bytes (assuming 3) into a destination of size 1
  188 |         snprintf(kv_store, size_needed, "%s%s", kv->key, kv->reference);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Ticket: #7905.
pull/13926/head
Victor Julien 2 months ago committed by Victor Julien
parent 40363f7465
commit a57643c70b

@ -182,8 +182,9 @@ static void AlertJsonReference(const PacketAlert *pa, SCJsonBuilder *jb)
while (kv) {
/* Note that the key and reference sizes have been bound
* checked during parsing
* add +2 to safisfy gcc 15 + -Wformat-truncation=2
*/
const size_t size_needed = kv->key_len + kv->reference_len + 1;
const size_t size_needed = kv->key_len + kv->reference_len + 3;
char kv_store[size_needed];
snprintf(kv_store, size_needed, "%s%s", kv->key, kv->reference);
SCJbAppendString(jb, kv_store);

Loading…
Cancel
Save