From 52d0ac81eee3462c6839c7374ffe57329f7702b7 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 13 May 2018 00:48:31 +0200 Subject: Zero node padding before passing to reader sinks --- src/node.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src/node.c') diff --git a/src/node.c b/src/node.c index 32852dc1..0b0a51eb 100644 --- a/src/node.c +++ b/src/node.c @@ -217,6 +217,24 @@ serd_node_new_uri(const char* str) return serd_node_new_simple(SERD_URI, str); } +/** + Zero node padding. + + This is used for nodes which live in re-used stack memory during reading, + which must be normalized before being passed to a sink so comparison will + work correctly. +*/ +void +serd_node_zero_pad(SerdNode* node) +{ + char* buf = serd_node_buffer(node); + const size_t size = node->n_bytes; + const size_t padded_size = serd_node_pad_size(node->n_bytes); + if (padded_size > size) { + memset(buf + size, 0, padded_size - size); + } +} + SERD_API SerdNode* serd_node_copy(const SerdNode* node) @@ -226,6 +244,13 @@ serd_node_copy(const SerdNode* node) } const size_t size = serd_node_total_size(node); +#ifndef NDEBUG + const size_t unpadded_size = node->n_bytes; + const size_t padded_size = serd_node_pad_size(node->n_bytes); + 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*)calloc(1, size + 3); memcpy(copy, node, size); return copy; -- cgit v1.2.1