aboutsummaryrefslogtreecommitdiffstats
path: root/src/writer.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2019-05-05 14:10:27 +0200
committerDavid Robillard <d@drobilla.net>2020-06-21 18:12:04 +0200
commita74bb1f0c7f78b6d3dcf5b7bb5bb8a5838b68be5 (patch)
tree4d1dde9724131ca53c849770e122e6602fb187a8 /src/writer.c
parent94ee2a1e547702b2e45de6c9849dede5fbaa93e8 (diff)
downloadserd-a74bb1f0c7f78b6d3dcf5b7bb5bb8a5838b68be5.tar.gz
serd-a74bb1f0c7f78b6d3dcf5b7bb5bb8a5838b68be5.tar.bz2
serd-a74bb1f0c7f78b6d3dcf5b7bb5bb8a5838b68be5.zip
Improve add and chop prefix functions when given empty strings
Diffstat (limited to 'src/writer.c')
-rw-r--r--src/writer.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/writer.c b/src/writer.c
index 0fb12dc3..eab902c6 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);
}