diff options
author | David Robillard <d@drobilla.net> | 2019-05-05 14:10:27 +0200 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2020-10-27 13:13:58 +0100 |
commit | d459c6044e3bfdacded8d21c49315cf447e22d3e (patch) | |
tree | 52dc400ca3a7e4654d2d90425b658307ab11c66d /src | |
parent | 21b6a8c6e6854e84821b59255b11f256f0e11630 (diff) | |
download | serd-d459c6044e3bfdacded8d21c49315cf447e22d3e.tar.gz serd-d459c6044e3bfdacded8d21c49315cf447e22d3e.tar.bz2 serd-d459c6044e3bfdacded8d21c49315cf447e22d3e.zip |
Improve add and chop prefix functions when given empty strings
Diffstat (limited to 'src')
-rw-r--r-- | src/reader.c | 9 | ||||
-rw-r--r-- | src/writer.c | 9 |
2 files changed, 10 insertions, 8 deletions
diff --git a/src/reader.c b/src/reader.c index 6a4b0dc2..86960857 100644 --- a/src/reader.c +++ b/src/reader.c @@ -207,14 +207,15 @@ serd_reader_free(SerdReader* reader) } void -serd_reader_add_blank_prefix(SerdReader* reader, - const char* prefix) +serd_reader_add_blank_prefix(SerdReader* reader, const char* prefix) { free(reader->bprefix); reader->bprefix_len = 0; reader->bprefix = NULL; - if (prefix) { - reader->bprefix_len = strlen(prefix); + + const size_t prefix_len = prefix ? strlen(prefix) : 0; + if (prefix_len) { + reader->bprefix_len = prefix_len; reader->bprefix = (char*)malloc(reader->bprefix_len + 1); memcpy(reader->bprefix, prefix, reader->bprefix_len + 1); } diff --git a/src/writer.c b/src/writer.c index a6c5f8c7..cd6b8437 100644 --- a/src/writer.c +++ b/src/writer.c @@ -1042,14 +1042,15 @@ serd_writer_new(SerdWorld* world, } void -serd_writer_chop_blank_prefix(SerdWriter* writer, - const char* prefix) +serd_writer_chop_blank_prefix(SerdWriter* writer, const char* prefix) { free(writer->bprefix); writer->bprefix_len = 0; writer->bprefix = NULL; - if (prefix) { - writer->bprefix_len = strlen(prefix); + + const size_t prefix_len = prefix ? strlen(prefix) : 0; + if (prefix_len) { + writer->bprefix_len = prefix_len; writer->bprefix = (char*)malloc(writer->bprefix_len + 1); memcpy(writer->bprefix, prefix, writer->bprefix_len + 1); } |