aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/node.c41
-rw-r--r--src/reader.h9
2 files changed, 37 insertions, 13 deletions
diff --git a/src/node.c b/src/node.c
index f7ee0457..f384e6ea 100644
--- a/src/node.c
+++ b/src/node.c
@@ -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;
}
diff --git a/src/reader.h b/src/reader.h
index 7f5fe521..00a41794 100644
--- a/src/reader.h
+++ b/src/reader.h
@@ -146,15 +146,14 @@ push_byte(SerdReader* reader, SerdNode* node, const int c)
{
assert(c != EOF);
- char* const s = (char*)serd_stack_push(&reader->stack, 1);
- if (!s) {
+ if (reader->stack.size + 1 > reader->stack.buf_size) {
return SERD_BAD_STACK;
}
- *(s - 1) = (char)c;
- *s = '\0';
-
+ ((uint8_t*)reader->stack.buf)[reader->stack.size - 1] = (uint8_t)c;
+ ++reader->stack.size;
++node->length;
+
return SERD_SUCCESS;
}