Browse Source

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.
zrythm_meson
David Robillard 2 years ago
parent
commit
0b187ad97c
  1. 23
      src/node.c

23
src/node.c

@ -189,23 +189,28 @@ serd_node_new_file_uri(const uint8_t* path, @@ -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);

Loading…
Cancel
Save