aboutsummaryrefslogtreecommitdiffstats
path: root/src/reader.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2020-11-13 11:58:17 +0100
committerDavid Robillard <d@drobilla.net>2020-11-13 12:53:28 +0100
commitf63257a60cda79963ba7d046f52b66c3b13e2c9a (patch)
tree439d49161e6ed1eb1f5dbd4079fd7b3530b5e2bd /src/reader.c
parent353b92d13d3ab6276998239c827287151e16bc8d (diff)
downloadserd-f63257a60cda79963ba7d046f52b66c3b13e2c9a.tar.gz
serd-f63257a60cda79963ba7d046f52b66c3b13e2c9a.tar.bz2
serd-f63257a60cda79963ba7d046f52b66c3b13e2c9a.zip
Improve add and chop prefix functions when given empty strings
Diffstat (limited to 'src/reader.c')
-rw-r--r--src/reader.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/reader.c b/src/reader.c
index 5d33e45d..fd859bf8 100644
--- a/src/reader.c
+++ b/src/reader.c
@@ -245,14 +245,15 @@ serd_reader_get_handle(const SerdReader* reader)
}
void
-serd_reader_add_blank_prefix(SerdReader* reader,
- const uint8_t* prefix)
+serd_reader_add_blank_prefix(SerdReader* reader, const uint8_t* prefix)
{
free(reader->bprefix);
reader->bprefix_len = 0;
reader->bprefix = NULL;
- if (prefix) {
- reader->bprefix_len = strlen((const char*)prefix);
+
+ const size_t prefix_len = prefix ? strlen((const char*)prefix) : 0;
+ if (prefix_len) {
+ reader->bprefix_len = prefix_len;
reader->bprefix = (uint8_t*)malloc(reader->bprefix_len + 1);
memcpy(reader->bprefix, prefix, reader->bprefix_len + 1);
}