diff options
Diffstat (limited to 'src/node.c')
-rw-r--r-- | src/node.c | 41 |
1 files changed, 33 insertions, 8 deletions
@@ -112,6 +112,23 @@ serd_node_maybe_get_meta_c(const SerdNode* const node) return (node->flags & meta_mask) ? serd_node_meta_c(node) : NULL; } +static void +serd_node_check_padding(const SerdNode* node) +{ + (void)node; +#ifndef NDEBUG + if (node) { + const size_t unpadded_size = node->length; + const size_t padded_size = serd_node_pad_size(unpadded_size); + for (size_t i = 0; i < padded_size - unpadded_size; ++i) { + assert(serd_node_buffer_c(node)[unpadded_size + i] == '\0'); + } + + serd_node_check_padding(serd_node_maybe_get_meta_c(node)); + } +#endif +} + static SERD_PURE_FUNC size_t serd_node_total_size(const SerdNode* const node) { @@ -188,6 +205,8 @@ serd_new_token(const SerdNodeType type, const SerdStringView str) node->length = length; } + serd_node_check_padding(node); + return node; } @@ -201,6 +220,7 @@ serd_new_string(const SerdStringView str) memcpy(serd_node_buffer(node), str.data, str.length); node->length = length; + serd_node_check_padding(node); return node; } @@ -226,7 +246,9 @@ serd_new_plain_literal_i(const SerdStringView str, lang_node->type = SERD_LITERAL; lang_node->length = lang.length; memcpy(serd_node_buffer(lang_node), lang.data, lang.length); + serd_node_check_padding(lang_node); + serd_node_check_padding(node); return node; } @@ -272,7 +294,9 @@ serd_new_typed_literal(const SerdStringView str, datatype_node->type = SERD_URI; memcpy( serd_node_buffer(datatype_node), datatype_uri.data, datatype_uri.length); + serd_node_check_padding(datatype_node); + serd_node_check_padding(node); return node; } @@ -296,14 +320,8 @@ serd_node_copy(const SerdNode* node) } const size_t size = serd_node_total_size(node); -#ifndef NDEBUG - const size_t unpadded_size = node->length; - const size_t padded_size = serd_node_pad_size(node->length); - for (size_t i = 0; i < padded_size - unpadded_size; ++i) { - assert(serd_node_buffer_c(node)[unpadded_size + i] == '\0'); - } -#endif - SerdNode* copy = (SerdNode*)serd_calloc_aligned(serd_node_align, size); + SerdNode* copy = (SerdNode*)serd_calloc_aligned(serd_node_align, size); + memcpy(copy, node, size); return copy; } @@ -354,6 +372,7 @@ serd_new_parsed_uri(const SerdURIView uri) serd_node_buffer(node)[actual_len] = '\0'; node->length = actual_len; + serd_node_check_padding(node); return node; } @@ -369,6 +388,7 @@ serd_new_from_uri(const SerdURIView uri, const SerdURIView base) serd_node_buffer(node)[actual_len] = '\0'; node->length = actual_len; + serd_node_check_padding(node); return node; } @@ -383,6 +403,7 @@ serd_new_resolved_uri(const SerdStringView string, const SerdURIView base) return NULL; } + serd_node_check_padding(result); return result; } @@ -477,6 +498,7 @@ serd_new_file_uri(const SerdStringView path, const SerdStringView hostname) SerdNode* const node = serd_new_string(serd_substring(string, length)); free(buffer.buf); + serd_node_check_padding(node); return node; } @@ -555,6 +577,7 @@ serd_new_decimal(const double d, } memcpy(serd_node_meta(node), type, type_len); + serd_node_check_padding(node); return node; } @@ -585,6 +608,7 @@ serd_new_integer(const int64_t i, const SerdNode* const datatype) } while ((abs_i /= 10) > 0); memcpy(serd_node_meta(node), type, type_len); + serd_node_check_padding(node); return node; } @@ -613,6 +637,7 @@ serd_new_blob(const void* const buf, node->length = len; memcpy(serd_node_meta(node), type, type_len); + serd_node_check_padding(node); return node; } |