diff options
author | David Robillard <d@drobilla.net> | 2023-02-28 22:39:02 -0500 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2023-03-31 11:11:18 -0400 |
commit | 2eb037b3f1abebbac697c7d804f1e6339c907aaa (patch) | |
tree | 8415167f522266de46a6b9eaa2f1600f1617bef6 | |
parent | 4ad14a612a188ae04efcecb2949e4c7c2af191f2 (diff) | |
download | serd-2eb037b3f1abebbac697c7d804f1e6339c907aaa.tar.gz serd-2eb037b3f1abebbac697c7d804f1e6339c907aaa.tar.bz2 serd-2eb037b3f1abebbac697c7d804f1e6339c907aaa.zip |
Fix possible hang when writing nested Turtle lists
-rw-r--r-- | NEWS | 3 | ||||
-rw-r--r-- | src/writer.c | 19 |
2 files changed, 15 insertions, 7 deletions
@@ -10,6 +10,7 @@ serd (0.31.0) unstable; urgency=medium * Fix crash when trying to read chunks without starting * Fix hang when skipping an error at EOF when lax parsing * Fix incorrect parsing of strange quote escape patterns + * Fix possible hang when writing nested Turtle lists * Gracefully handle bad characters in Turtle blank node syntax * Gracefully handle bad characters in Turtle datatype syntax * Improve serdi man page @@ -17,7 +18,7 @@ serd (0.31.0) unstable; urgency=medium * Replace duplicated dox_to_sphinx script with sphinxygen dependency * Test header for warnings more strictly - -- David Robillard <d@drobilla.net> Wed, 01 Mar 2023 00:36:43 +0000 + -- David Robillard <d@drobilla.net> Wed, 01 Mar 2023 03:38:47 +0000 serd (0.30.16) stable; urgency=medium diff --git a/src/writer.c b/src/writer.c index 575d3fb9..d4b47e0a 100644 --- a/src/writer.c +++ b/src/writer.c @@ -1,4 +1,4 @@ -// Copyright 2011-2020 David Robillard <d@drobilla.net> +// Copyright 2011-2023 David Robillard <d@drobilla.net> // SPDX-License-Identifier: ISC #include "byte_sink.h" @@ -122,6 +122,14 @@ supports_uriref(const SerdWriter* writer) } static void +deindent(SerdWriter* writer) +{ + if (writer->indent) { + --writer->indent; + } +} + +static void w_err(SerdWriter* writer, SerdStatus st, const char* fmt, ...) { /* TODO: This results in errors with no file information, which is not @@ -766,7 +774,7 @@ write_list_obj(SerdWriter* writer, const SerdNode* lang) { if (!strcmp((const char*)object->buf, NS_RDF "nil")) { - --writer->indent; + deindent(writer); write_sep(writer, SEP_LIST_END); return true; } @@ -856,7 +864,7 @@ serd_writer_write_statement(SerdWriter* writer, write_sep(writer, SEP_END_O); write_node(writer, object, datatype, lang, FIELD_OBJECT, flags); if (!(flags & SERD_ANON_O_BEGIN)) { - --writer->indent; + deindent(writer); } } else { // Abbreviate S @@ -868,8 +876,7 @@ serd_writer_write_statement(SerdWriter* writer, } else { // No abbreviation if (writer->context.subject.type) { - assert(writer->indent > 0); - --writer->indent; + deindent(writer); if (serd_stack_is_empty(&writer->anon_stack)) { write_sep(writer, SEP_END_S); } @@ -926,7 +933,7 @@ serd_writer_end_anon(SerdWriter* writer, const SerdNode* node) return SERD_ERR_UNKNOWN; } - --writer->indent; + deindent(writer); write_sep(writer, SEP_ANON_END); free_context(writer); writer->context = *anon_stack_top(writer); |