summaryrefslogtreecommitdiffstats
path: root/src/sratom.c
diff options
context:
space:
mode:
authorMartin Liska <mliska@suse.cz>2022-04-11 09:14:28 +0200
committerDavid Robillard <d@drobilla.net>2022-05-09 18:21:21 -0400
commit2edb78cc997b80493a5635d0dcecf4a25203d2a9 (patch)
tree01eaf49e2b5c7a9aa209429712418088732b74dd /src/sratom.c
parentc46452c83d442de137fa6470ba544e3ba142e923 (diff)
downloadsratom-2edb78cc997b80493a5635d0dcecf4a25203d2a9.tar.gz
sratom-2edb78cc997b80493a5635d0dcecf4a25203d2a9.tar.bz2
sratom-2edb78cc997b80493a5635d0dcecf4a25203d2a9.zip
Fix -D_FORTIFY_SOURCE=3 warning
Correctly set maximum buffer length for snprintf call.
Diffstat (limited to 'src/sratom.c')
-rw-r--r--src/sratom.c6
1 files changed, 4 insertions, 2 deletions
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;