diff options
author | David Robillard <d@drobilla.net> | 2020-06-20 20:58:27 +0200 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2020-10-27 13:13:59 +0100 |
commit | 44afc616ada1315bfcc1f2fb6bd82656ced8b2f5 (patch) | |
tree | bff66abc7b8df8bd0a4e081e21b2c388f6635b95 | |
parent | f9c7cac95abb7c5430c9ecd6f0a7220c3f8b5205 (diff) | |
download | serd-44afc616ada1315bfcc1f2fb6bd82656ced8b2f5.tar.gz serd-44afc616ada1315bfcc1f2fb6bd82656ced8b2f5.tar.bz2 serd-44afc616ada1315bfcc1f2fb6bd82656ced8b2f5.zip |
Make const Env functions tolerant of NULL
This is convenient in places where you don't necessarily need an Env, since in
this case these methods work the same as if with an empty Env.
-rw-r--r-- | src/env.c | 10 | ||||
-rw-r--r-- | tests/env_test.c | 4 |
2 files changed, 13 insertions, 1 deletions
@@ -108,7 +108,7 @@ serd_env_get_parsed_base_uri(const SerdEnv* env) const SerdNode* serd_env_base_uri(const SerdEnv* env) { - return env->base_uri_node; + return env ? env->base_uri_node : NULL; } SerdStatus @@ -204,6 +204,10 @@ serd_env_qualify_in_place(const SerdEnv* env, const SerdNode** prefix, SerdStringView* 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) { @@ -263,6 +267,10 @@ serd_env_expand_in_place(const SerdEnv* env, SerdStringView* uri_prefix, SerdStringView* uri_suffix) { + if (!env) { + return SERD_ERR_BAD_CURIE; + } + const char* const str = serd_node_string(curie); const char* const colon = (const char*)memchr(str, ':', curie->n_bytes + 1); if (curie->type != SERD_CURIE || !colon) { diff --git a/tests/env_test.c b/tests/env_test.c index cc04366d..cff8e3cf 100644 --- a/tests/env_test.c +++ b/tests/env_test.c @@ -46,6 +46,10 @@ test_env(void) SerdEnv* env = serd_env_new(NULL); serd_env_set_prefix(env, pre, eg); + assert(!serd_env_base_uri(NULL)); + assert(!serd_env_expand(NULL, NULL)); + assert(!serd_env_qualify(NULL, NULL)); + assert(!serd_env_base_uri(env)); assert(serd_env_set_base_uri(env, NULL)); assert(serd_env_set_base_uri(env, empty)); |