Browse Source

Improve add and chop prefix functions when given empty strings

zrythm_meson
David Robillard 2 years ago
parent
commit
f63257a60c
  1. 9
      src/reader.c
  2. 9
      src/writer.c

9
src/reader.c

@ -245,14 +245,15 @@ serd_reader_get_handle(const SerdReader* reader) @@ -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);
}

9
src/writer.c

@ -903,14 +903,15 @@ serd_writer_set_error_sink(SerdWriter* writer, @@ -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);
}

Loading…
Cancel
Save