From fb95ceca3b744e47e973585aa682515365ac9eb0 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 8 Jul 2021 16:15:46 -0400 Subject: Use a fixed-size reader stack --- test/meson.build | 5 +++++ test/test_reader_writer.c | 20 ++++++++++++-------- 2 files changed, 17 insertions(+), 8 deletions(-) (limited to 'test') diff --git a/test/meson.build b/test/meson.build index 5742c545..d9a386c3 100644 --- a/test/meson.build +++ b/test/meson.build @@ -159,6 +159,10 @@ simple_command_tests = { ['-i', 'turtle'], ['-i', 'unknown'], ['-i'], + ['-k', '-1'], + ['-k', '1024junk'], + ['-k', '9223372036854775807'], + ['-k'], ['-o', 'unknown'], ['-o'], ['-p'], @@ -264,6 +268,7 @@ test_suites = { '--', '-a', ['-i', 'NTriples'], + ['-k', '1024'], ], 'trig': [ files('w3c/trig/manifest.ttl'), diff --git a/test/test_reader_writer.c b/test/test_reader_writer.c index 1c028080..0ef8a96b 100644 --- a/test/test_reader_writer.c +++ b/test/test_reader_writer.c @@ -186,7 +186,7 @@ test_read_nquads_chunks(const char* const path) ReaderTest* const rt = (ReaderTest*)calloc(1, sizeof(ReaderTest)); SerdSink* const sink = serd_sink_new(rt, NULL); - SerdReader* const reader = serd_reader_new(SERD_NQUADS, sink); + SerdReader* const reader = serd_reader_new(SERD_NQUADS, sink, 4096); assert(reader); assert(sink); @@ -268,7 +268,7 @@ test_read_turtle_chunks(const char* const path) ReaderTest* const rt = (ReaderTest*)calloc(1, sizeof(ReaderTest)); SerdSink* const sink = serd_sink_new(rt, NULL); - SerdReader* const reader = serd_reader_new(SERD_TURTLE, sink); + SerdReader* const reader = serd_reader_new(SERD_TURTLE, sink, 4096); assert(reader); assert(sink); @@ -352,7 +352,7 @@ test_read_string(void) { ReaderTest* rt = (ReaderTest*)calloc(1, sizeof(ReaderTest)); SerdSink* sink = serd_sink_new(rt, NULL); - SerdReader* reader = serd_reader_new(SERD_TURTLE, sink); + SerdReader* reader = serd_reader_new(SERD_TURTLE, sink, 4096); assert(reader); assert(sink); @@ -433,7 +433,7 @@ test_write_errors(void) serd_writer_new(syntax, style, env, faulty_sink, &ctx); const SerdSink* const sink = serd_writer_sink(writer); - SerdReader* const reader = serd_reader_new(SERD_TRIG, sink); + SerdReader* const reader = serd_reader_new(SERD_TRIG, sink, 4096U); serd_reader_set_error_sink(reader, quiet_error_sink, NULL); serd_writer_set_error_sink(writer, quiet_error_sink, NULL); @@ -542,17 +542,21 @@ test_writer(const char* const path) static void test_reader(const char* path) { - ReaderTest rt = {0, 0, 0, 0, NULL}; - SerdSink* const sink = serd_sink_new(&rt, NULL); - SerdReader* reader = serd_reader_new(SERD_TURTLE, sink); + ReaderTest rt = {0, 0, 0, 0, NULL}; + SerdSink* const sink = serd_sink_new(&rt, NULL); assert(sink); - assert(reader); serd_sink_set_base_func(sink, test_base_sink); serd_sink_set_prefix_func(sink, test_prefix_sink); serd_sink_set_statement_func(sink, test_statement_sink); serd_sink_set_end_func(sink, test_end_sink); + // Test that too little stack space fails gracefully + assert(!serd_reader_new(SERD_TURTLE, sink, 32)); + + SerdReader* reader = serd_reader_new(SERD_TURTLE, sink, 4096); + assert(reader); + assert(serd_reader_read_chunk(reader) == SERD_FAILURE); assert(serd_reader_read_document(reader) == SERD_FAILURE); -- cgit v1.2.1