diff options
author | David Robillard <d@drobilla.net> | 2020-11-13 11:58:17 +0100 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2020-11-13 12:53:28 +0100 |
commit | f63257a60cda79963ba7d046f52b66c3b13e2c9a (patch) | |
tree | 439d49161e6ed1eb1f5dbd4079fd7b3530b5e2bd /src/writer.c | |
parent | 353b92d13d3ab6276998239c827287151e16bc8d (diff) | |
download | serd-f63257a60cda79963ba7d046f52b66c3b13e2c9a.tar.gz serd-f63257a60cda79963ba7d046f52b66c3b13e2c9a.tar.bz2 serd-f63257a60cda79963ba7d046f52b66c3b13e2c9a.zip |
Improve add and chop prefix functions when given empty strings
Diffstat (limited to 'src/writer.c')
-rw-r--r-- | src/writer.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/writer.c b/src/writer.c index 5c84b950..c821d904 100644 --- a/src/writer.c +++ b/src/writer.c @@ -903,14 +903,15 @@ serd_writer_set_error_sink(SerdWriter* writer, } void -serd_writer_chop_blank_prefix(SerdWriter* writer, - const uint8_t* prefix) +serd_writer_chop_blank_prefix(SerdWriter* writer, const uint8_t* prefix) { free(writer->bprefix); writer->bprefix_len = 0; writer->bprefix = NULL; - if (prefix) { - writer->bprefix_len = strlen((const char*)prefix); + + const size_t prefix_len = prefix ? strlen((const char*)prefix) : 0; + if (prefix_len) { + writer->bprefix_len = prefix_len; writer->bprefix = (uint8_t*)malloc(writer->bprefix_len + 1); memcpy(writer->bprefix, prefix, writer->bprefix_len + 1); } |