aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2021-06-30 16:15:15 -0400
committerDavid Robillard <d@drobilla.net>2021-06-30 16:19:59 -0400
commitc1cae48eb3851239817c8cda5a8266815fb3173e (patch)
treec9ceda4eb0fa59b12a269b665c9822c719a1c80b /src
parent8113202c98888e092e1f4cdc2ee3ab34509d949c (diff)
downloadserd-c1cae48eb3851239817c8cda5a8266815fb3173e.tar.gz
serd-c1cae48eb3851239817c8cda5a8266815fb3173e.tar.bz2
serd-c1cae48eb3851239817c8cda5a8266815fb3173e.zip
Make node qualify and expand functions tolerate a null Env
This is convenient in places where you don't necessarily need an Env, since these methods will work the same as with an empty Env.
Diffstat (limited to 'src')
-rw-r--r--src/env.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/env.c b/src/env.c
index ad0252fb..385ab2f6 100644
--- a/src/env.c
+++ b/src/env.c
@@ -179,6 +179,10 @@ serd_env_qualify(const SerdEnv* const env,
SerdNode* const prefix,
SerdChunk* const suffix)
{
+ if (!env) {
+ return false;
+ }
+
for (size_t i = 0; i < env->n_prefixes; ++i) {
const SerdNode* const prefix_uri = &env->prefixes[i].uri;
if (uri->n_bytes >= prefix_uri->n_bytes) {
@@ -201,6 +205,10 @@ serd_env_expand(const SerdEnv* const env,
SerdChunk* const uri_prefix,
SerdChunk* const uri_suffix)
{
+ if (!env) {
+ return SERD_ERR_BAD_CURIE;
+ }
+
const uint8_t* const colon =
(const uint8_t*)memchr(curie->buf, ':', curie->n_bytes + 1);
if (curie->type != SERD_CURIE || !colon) {
@@ -222,6 +230,10 @@ serd_env_expand(const SerdEnv* const env,
SerdNode
serd_env_expand_node(const SerdEnv* const env, const SerdNode* const node)
{
+ if (!env) {
+ return SERD_NODE_NULL;
+ }
+
switch (node->type) {
case SERD_NOTHING:
case SERD_LITERAL: