aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/reader.c4
-rw-r--r--src/stack.h19
-rw-r--r--test/test_overflow.c4
3 files changed, 13 insertions, 14 deletions
diff --git a/src/reader.c b/src/reader.c
index e819d472..5ff2cbd9 100644
--- a/src/reader.c
+++ b/src/reader.c
@@ -173,7 +173,7 @@ serd_reader_new(SerdWorld* const world,
me->world = world;
me->sink = sink;
- me->stack = serd_stack_new(stack_size);
+ me->stack = serd_stack_new(stack_size, serd_node_align);
me->syntax = syntax;
me->next_id = 1;
me->strict = !(flags & SERD_READ_LAX);
@@ -202,7 +202,7 @@ serd_reader_free(SerdReader* const reader)
serd_reader_finish(reader);
- free(reader->stack.buf);
+ serd_free_aligned(reader->stack.buf);
free(reader->bprefix);
free(reader);
}
diff --git a/src/stack.h b/src/stack.h
index cdf2b0f6..20bd561b 100644
--- a/src/stack.h
+++ b/src/stack.h
@@ -4,15 +4,13 @@
#ifndef SERD_SRC_STACK_H
#define SERD_SRC_STACK_H
+#include "system.h"
+
#include <assert.h>
#include <stdbool.h>
#include <stddef.h>
-#include <stdlib.h>
#include <string.h>
-/** An offset to start the stack at. Note 0 is reserved for NULL. */
-#define SERD_STACK_BOTTOM sizeof(void*)
-
/** A dynamic stack in memory. */
typedef struct {
char* buf; ///< Stack memory
@@ -20,23 +18,22 @@ typedef struct {
size_t size; ///< Conceptual size of stack in buf
} SerdStack;
-/** An offset to start the stack at. Note 0 is reserved for NULL. */
-#define SERD_STACK_BOTTOM sizeof(void*)
-
static inline SerdStack
-serd_stack_new(size_t size)
+serd_stack_new(size_t size, size_t align)
{
+ const size_t aligned_size = (size + (align - 1)) / align * align;
+
SerdStack stack;
- stack.buf = (char*)calloc(size, 1);
+ stack.buf = (char*)serd_calloc_aligned(align, aligned_size);
stack.buf_size = size;
- stack.size = SERD_STACK_BOTTOM;
+ stack.size = align; // 0 is reserved for null
return stack;
}
static inline void
serd_stack_free(SerdStack* stack)
{
- free(stack->buf);
+ serd_free_aligned(stack->buf);
stack->buf = NULL;
stack->buf_size = 0;
stack->size = 0;
diff --git a/test/test_overflow.c b/test/test_overflow.c
index 6c67d7cc..bc0a2aaf 100644
--- a/test/test_overflow.c
+++ b/test/test_overflow.c
@@ -75,12 +75,14 @@ static void
test_turtle_overflow(void)
{
static const char* const test_strings[] = {
+ "<http://example.org/s> <http://example.org/p> :%99 .",
"<http://example.org/s> <http://example.org/p> <http://example.org/> .",
"<http://example.org/s> <http://example.org/p> "
"<thisisanabsurdlylongurischeme://because/testing/> .",
+ "<http://example.org/s> <http://example.org/p> eg:foo .",
"<http://example.org/s> <http://example.org/p> 1234 .",
"<http://example.org/s> <http://example.org/p> (1 2 3 4) .",
- "<http://example.org/s> <http://example.org/p> ((((((((42)))))))) .",
+ "<http://example.org/s> <http://example.org/p> (((((((42))))))) .",
"<http://example.org/s> <http://example.org/p> \"literal\" .",
"<http://example.org/s> <http://example.org/p> _:blank .",
"<http://example.org/s> <http://example.org/p> true .",