aboutsummaryrefslogtreecommitdiffstats
path: root/src/env.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/env.c')
-rw-r--r--src/env.c28
1 files changed, 16 insertions, 12 deletions
diff --git a/src/env.c b/src/env.c
index d4ae1937..434d1a3b 100644
--- a/src/env.c
+++ b/src/env.c
@@ -258,7 +258,7 @@ serd_env_expand_in_place(const SerdEnv* const env,
return SERD_ERR_BAD_CURIE;
}
- uri_prefix->buf = serd_node_string(prefix->uri);
+ uri_prefix->buf = prefix->uri ? serd_node_string(prefix->uri) : "";
uri_prefix->len = prefix->uri ? prefix->uri->length : 0;
uri_suffix->buf = colon + 1;
uri_suffix->len = curie.len - name_len - 1;
@@ -279,20 +279,24 @@ serd_env_expand_curie(const SerdEnv* const env, const SerdStringView curie)
return NULL;
}
- const size_t len = prefix.len + suffix.len;
- SerdNode* const ret = serd_node_malloc(len, 0u, SERD_URI);
- if (!ret) {
- return NULL;
- }
+ const size_t len = prefix.len + suffix.len;
- char* const string = serd_node_buffer(ret);
- assert(string);
- assert(prefix.buf);
+ const size_t real_length = serd_node_pad_length(len);
+ const size_t node_size = sizeof(SerdNode) + real_length;
+ SerdNode* node = serd_node_malloc(node_size);
- memcpy(string, prefix.buf, prefix.len);
- memcpy(string + prefix.len, suffix.buf, suffix.len);
+ if (node) {
+ node->length = len;
+ node->flags = 0u;
+ node->type = SERD_URI;
+
+ char* const string = (char*)(node + 1u);
+ assert(prefix.buf);
+ memcpy(string, prefix.buf, prefix.len);
+ memcpy(string + prefix.len, suffix.buf, suffix.len);
+ }
- return ret;
+ return node;
}
SerdNode*