diff options
author | David Robillard <d@drobilla.net> | 2022-11-24 17:34:21 -0500 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2022-11-25 07:05:57 -0500 |
commit | 292d101ed3b8a0b3d79d45af48feccba827c0942 (patch) | |
tree | f266360c7eaa329e3277008f68fa127b6c75d85a /src | |
parent | d40a7fe79847ab46e544d9fbb845affbe876c0db (diff) | |
download | serd-292d101ed3b8a0b3d79d45af48feccba827c0942.tar.gz serd-292d101ed3b8a0b3d79d45af48feccba827c0942.tar.bz2 serd-292d101ed3b8a0b3d79d45af48feccba827c0942.zip |
Always handle the return value of serd_env_set_base_uri()
Diffstat (limited to 'src')
-rw-r--r-- | src/env.c | 7 | ||||
-rw-r--r-- | src/writer.c | 29 |
2 files changed, 20 insertions, 16 deletions
@@ -25,8 +25,11 @@ SerdEnv* serd_env_new(const SerdNode* const base_uri) { SerdEnv* env = (SerdEnv*)calloc(1, sizeof(struct SerdEnvImpl)); - if (env && base_uri) { - serd_env_set_base_uri(env, base_uri); + if (env && base_uri && base_uri->type != SERD_NOTHING) { + if (serd_env_set_base_uri(env, base_uri)) { + free(env); + return NULL; + } } return env; diff --git a/src/writer.c b/src/writer.c index 26ed01c0..d2609cf5 100644 --- a/src/writer.c +++ b/src/writer.c @@ -1010,23 +1010,24 @@ serd_writer_chop_blank_prefix(SerdWriter* writer, const uint8_t* prefix) SerdStatus serd_writer_set_base_uri(SerdWriter* writer, const SerdNode* uri) { - if (!serd_env_set_base_uri(writer->env, uri)) { - serd_env_get_base_uri(writer->env, &writer->base_uri); + const SerdStatus st = serd_env_set_base_uri(writer->env, uri); + if (st) { + return st; + } - if (writer->syntax == SERD_TURTLE || writer->syntax == SERD_TRIG) { - if (writer->context.graph.type || writer->context.subject.type) { - sink(" .\n\n", 4, writer); - reset_context(writer, true); - } - sink("@base <", 7, writer); - sink(uri->buf, uri->n_bytes, writer); - sink("> .\n", 4, writer); + serd_env_get_base_uri(writer->env, &writer->base_uri); + + if (writer->syntax == SERD_TURTLE || writer->syntax == SERD_TRIG) { + if (writer->context.graph.type || writer->context.subject.type) { + sink(" .\n\n", 4, writer); + reset_context(writer, true); } - writer->indent = 0; - return reset_context(writer, true); + sink("@base <", 7, writer); + sink(uri->buf, uri->n_bytes, writer); + sink("> .\n", 4, writer); } - - return SERD_ERR_UNKNOWN; + writer->indent = 0; + return reset_context(writer, true); } SerdStatus |