diff options
author | David Robillard <d@drobilla.net> | 2024-12-02 10:42:50 -0500 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2024-12-02 10:42:50 -0500 |
commit | 6ae2d5c4876ba82d1e08a16163a86128c17dc9db (patch) | |
tree | 05f45370e4c9ec32a3049d6a856b3d84c77ce349 /src/sratom.c | |
parent | 33d343f25ff41cab66cc679757d94f9af9b3e766 (diff) | |
download | sratom-6ae2d5c4876ba82d1e08a16163a86128c17dc9db.tar.gz sratom-6ae2d5c4876ba82d1e08a16163a86128c17dc9db.tar.bz2 sratom-6ae2d5c4876ba82d1e08a16163a86128c17dc9db.zip |
Avoid snprintf when writing MIDI events
Diffstat (limited to 'src/sratom.c')
-rw-r--r-- | src/sratom.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/sratom.c b/src/sratom.c index 579f42f..b51be47 100644 --- a/src/sratom.c +++ b/src/sratom.c @@ -237,6 +237,8 @@ sratom_write(Sratom* sratom, uint32_t size, const void* body) { + static const char hex_chars[] = "0123456789ABCDEF"; + const char* const type = unmap->unmap(unmap->handle, type_urid); const uint8_t idbuf[12] = "b0000000000"; SerdNode id = serd_node_from_string(SERD_BLANK, idbuf); @@ -323,13 +325,12 @@ sratom_write(Sratom* sratom, new_node = true; datatype = serd_node_from_string(SERD_URI, USTR(LV2_MIDI__MidiEvent)); - const size_t len = (size_t)size * 2U; - uint8_t* const str = (uint8_t*)calloc(len + 1, 1); - for (uint32_t i = 0; i < size; ++i) { - snprintf((char*)str + ((size_t)2 * i), - len - ((size_t)2 * i) + 1U, - "%02X", - (unsigned)*((const uint8_t*)body + i)); + const size_t len = (size_t)size * 2U; + char* const str = (char*)calloc(len + 1, 1); + for (uint32_t i = 0U; i < size; ++i) { + const uint8_t byte = ((const uint8_t*)body)[i]; + str[2U * i] = hex_chars[byte >> 4U]; + str[2U * i + 1U] = hex_chars[byte & 0x0FU]; } object = serd_node_from_string(SERD_LITERAL, USTR(str)); |