diff options
author | David Robillard <d@drobilla.net> | 2021-01-09 19:17:29 +0100 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2021-01-09 19:25:31 +0100 |
commit | 0b187ad97c52a2443b8c2b2bef7c4c9e66508a65 (patch) | |
tree | f7a7f748e898253426e4b44cac2f0125f389abf0 /src | |
parent | b3a07044be6f31e20587011309b7798243ed93e0 (diff) | |
download | serd-0b187ad97c52a2443b8c2b2bef7c4c9e66508a65.tar.gz serd-0b187ad97c52a2443b8c2b2bef7c4c9e66508a65.tar.bz2 serd-0b187ad97c52a2443b8c2b2bef7c4c9e66508a65.zip |
Avoid GCC warning about printed string overflow
GCC seems to think there was a potential overflow here, but I don't see it. I
think it just can't figure out that the printed text and the size both depend
on the same variable. In any case, avoiding formatting functions here avoids
the warning, and is probably faster anyway.
Diffstat (limited to 'src')
-rw-r--r-- | src/node.c | 23 |
1 files changed, 14 insertions, 9 deletions
@@ -189,23 +189,28 @@ serd_node_new_file_uri(const uint8_t* path, { const size_t path_len = strlen((const char*)path); const size_t hostname_len = hostname ? strlen((const char*)hostname) : 0; - const bool evil = is_windows_path(path); + const bool is_windows = is_windows_path(path); size_t uri_len = 0; uint8_t* uri = NULL; - if (path[0] == '/' || is_windows_path(path)) { - uri_len = strlen("file://") + hostname_len + evil; + if (path[0] == '/' || is_windows) { + uri_len = strlen("file://") + hostname_len + is_windows; uri = (uint8_t*)malloc(uri_len + 1); - snprintf((char*)uri, - uri_len + 1, - "file://%s%s", - hostname ? (const char*)hostname : "", - evil ? "/" : ""); + + strcpy((char*)uri, "file://"); + + if (hostname) { + strcpy((char*)uri + 7, (char*)hostname); + } + + if (is_windows) { + ((char*)uri)[7 + hostname_len] = '/'; + } } SerdChunk chunk = {uri, uri_len}; for (size_t i = 0; i < path_len; ++i) { - if (evil && path[i] == '\\') { + if (is_windows && path[i] == '\\') { serd_chunk_sink("/", 1, &chunk); } else if (path[i] == '%') { serd_chunk_sink("%%", 2, &chunk); |