aboutsummaryrefslogtreecommitdiffstats
path: root/src/reader.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/reader.c')
-rw-r--r--src/reader.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/reader.c b/src/reader.c
index 44b17704..ceef5fb4 100644
--- a/src/reader.c
+++ b/src/reader.c
@@ -159,15 +159,26 @@ serd_reader_new(SerdWorld* const world,
const SerdSink* const sink,
const size_t stack_size)
{
+ if (stack_size < 8 * sizeof(SerdNode)) {
+ return NULL;
+ }
+
SerdReader* me = (SerdReader*)calloc(1, sizeof(SerdReader));
me->world = world;
me->sink = sink;
- me->stack = serd_stack_new(stack_size);
+ me->stack = serd_stack_new(stack_size, sizeof(SerdNode));
me->syntax = syntax;
me->next_id = 1;
me->strict = true;
+ /* Reserve a bit of space at the end of the stack to zero pad nodes. This
+ particular kind of overflow could be detected (in emit_statement), but
+ this is simpler and a bit more resilient to mistakes since the reader
+ generally pushes only a few bytes at a time, making it pretty unlikely
+ to overshoot the buffer by this much. */
+ me->stack.buf_size -= 8 * sizeof(size_t);
+
me->rdf_first = push_node(me, SERD_URI, NS_RDF "first", 48);
me->rdf_rest = push_node(me, SERD_URI, NS_RDF "rest", 47);
me->rdf_nil = push_node(me, SERD_URI, NS_RDF "nil", 46);