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 /src | |
parent | 4ad14a612a188ae04efcecb2949e4c7c2af191f2 (diff) | |
download | serd-2eb037b3f1abebbac697c7d804f1e6339c907aaa.tar.gz serd-2eb037b3f1abebbac697c7d804f1e6339c907aaa.tar.bz2 serd-2eb037b3f1abebbac697c7d804f1e6339c907aaa.zip |
Fix possible hang when writing nested Turtle lists
Diffstat (limited to 'src')
-rw-r--r-- | src/writer.c | 19 |
1 files changed, 13 insertions, 6 deletions
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); |