From 02d56e83931e53e1cde57247c64d56fda3804f77 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 1 Dec 2023 20:39:44 -0500 Subject: [WIP] Tighten up reader node management [WIP] Broken on 32-bit This makes the reader stack manipulations stricter, to make the code more regular and avoid redundant work and bad cache activity. Now, functions that push node headers and their bodies are responsible for (more or less) immediately pushing any trailing null bytes required for termination and alignment. This makes the writes to the node in the stack more local, ensures nodes are terminated as early as possible (to reduce the risk of using non-terminated strings), and avoids the need to calculate aligned stack allocations. --- src/node.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/node.c') diff --git a/src/node.c b/src/node.c index c89f20fd..56fcb4b6 100644 --- a/src/node.c +++ b/src/node.c @@ -229,7 +229,7 @@ serd_node_set(ZixAllocator* const allocator, which must be normalized before being passed to a sink so comparison will work correctly. */ -void +static void serd_node_zero_pad(SerdNode* node) { char* buf = serd_node_buffer(node); @@ -274,6 +274,8 @@ serd_node_construct_simple(const size_t buf_size, } serd_node_zero_pad(node); + assert(total_size % sizeof(SerdNode) == 0); + return result(SERD_SUCCESS, total_size); } @@ -612,7 +614,7 @@ serd_node_new(ZixAllocator* const allocator, const SerdNodeArgs args) assert(r.count % sizeof(SerdNode) == 0); SerdNode* const node = - serd_node_malloc(allocator, sizeof(SerdNode) + r.count + 1); + serd_node_malloc(allocator, sizeof(SerdNode) + r.count); if (node) { r = serd_node_construct(r.count, node, args); -- cgit v1.2.1