From 2edb78cc997b80493a5635d0dcecf4a25203d2a9 Mon Sep 17 00:00:00 2001 From: Martin Liska Date: Mon, 11 Apr 2022 09:14:28 +0200 Subject: Fix -D_FORTIFY_SOURCE=3 warning Correctly set maximum buffer length for snprintf call. --- src/sratom.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/sratom.c') diff --git a/src/sratom.c b/src/sratom.c index 692257d..53fa017 100644 --- a/src/sratom.c +++ b/src/sratom.c @@ -334,13 +334,15 @@ sratom_write(Sratom* sratom, new_node = true; datatype = serd_node_from_string(SERD_URI, USTR(LV2_MIDI__MidiEvent)); - uint8_t* str = (uint8_t*)calloc(size * 2 + 1, 1); + const size_t len = size * 2; + uint8_t* const str = (uint8_t*)calloc(len + 1, 1); for (uint32_t i = 0; i < size; ++i) { snprintf((char*)str + (2 * i), - size * 2 + 1, + len - (2 * i) + 1, "%02X", (unsigned)*((const uint8_t*)body + i)); } + object = serd_node_from_string(SERD_LITERAL, USTR(str)); } else if (type_urid == sratom->atom_Event) { const LV2_Atom_Event* ev = (const LV2_Atom_Event*)body; -- cgit v1.2.1