diff options
author | David Robillard <d@drobilla.net> | 2023-04-09 11:54:11 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2023-04-16 22:17:56 -0400 |
commit | a6cd7dd91d93015ec118286b868c3fd43133f3ac (patch) | |
tree | b10d88ca099c0d0986c2e48ccca62023a0ac1614 /src/n3.c | |
parent | 1d8cdcef2cc4aaf2e45cfab01a390d6eab56d525 (diff) | |
download | serd-a6cd7dd91d93015ec118286b868c3fd43133f3ac.tar.gz serd-a6cd7dd91d93015ec118286b868c3fd43133f3ac.tar.bz2 serd-a6cd7dd91d93015ec118286b868c3fd43133f3ac.zip |
Gracefully handle errors when writing text
Diffstat (limited to 'src/n3.c')
-rw-r--r-- | src/n3.c | 29 |
1 files changed, 14 insertions, 15 deletions
@@ -608,8 +608,8 @@ read_PN_LOCAL(SerdReader* const reader, const Ref dest, bool* const ate_dot) return r_err(reader, st, "bad escape\n"); } - if (st != SERD_SUCCESS && read_PN_CHARS_BASE(reader, dest)) { - return SERD_FAILURE; + if (st != SERD_SUCCESS && (st = read_PN_CHARS_BASE(reader, dest))) { + return st; } } @@ -659,11 +659,9 @@ read_PN_PREFIX_tail(SerdReader* const reader, const Ref dest) static SerdStatus read_PN_PREFIX(SerdReader* const reader, const Ref dest) { - if (!read_PN_CHARS_BASE(reader, dest)) { - return read_PN_PREFIX_tail(reader, dest); - } + const SerdStatus st = read_PN_CHARS_BASE(reader, dest); - return SERD_FAILURE; + return st ? st : read_PN_PREFIX_tail(reader, dest); } static SerdStatus @@ -989,10 +987,11 @@ read_verb(SerdReader* const reader, Ref* const dest) return SERD_SUCCESS; } - if (st > SERD_FAILURE || read_PrefixedName(reader, *dest, false, &ate_dot) || - ate_dot) { + if (st > SERD_FAILURE || + (st = read_PrefixedName(reader, *dest, false, &ate_dot)) || ate_dot) { *dest = pop_node(reader, *dest); - return r_err(reader, SERD_ERR_BAD_SYNTAX, "bad verb\n"); + st = st > SERD_FAILURE ? st : SERD_ERR_BAD_SYNTAX; + return r_err(reader, st, "bad verb\n"); } return SERD_SUCCESS; @@ -1125,8 +1124,9 @@ read_anon(SerdReader* const reader, *ctx.flags = old_flags; } - return (eat_byte_check(reader, ']') == ']') ? SERD_SUCCESS - : SERD_ERR_BAD_SYNTAX; + return st > SERD_FAILURE ? st + : (eat_byte_check(reader, ']') == ']') ? SERD_SUCCESS + : SERD_ERR_BAD_SYNTAX; } /* If emit is true: recurses, calling statement_sink for every statement @@ -1394,7 +1394,7 @@ read_subject(SerdReader* const reader, bool ate_dot = false; switch ((*s_type = peek_byte(reader))) { case '[': - read_anon(reader, ctx, true, dest); + st = read_anon(reader, ctx, true, dest); break; case '(': st = read_collection(reader, ctx, dest); @@ -1567,9 +1567,8 @@ read_wrappedGraph(SerdReader* const reader, ReadContext* const ctx) return r_err(reader, SERD_ERR_BAD_SYNTAX, "bad subject\n"); } - if (read_triples(reader, *ctx, &ate_dot) && s_type != '[') { - return r_err( - reader, SERD_ERR_BAD_SYNTAX, "missing predicate object list\n"); + if ((st = read_triples(reader, *ctx, &ate_dot)) && s_type != '[') { + return r_err(reader, st, "bad predicate object list\n"); } ctx->subject = pop_node(reader, ctx->subject); |