From 30aa350f3ed2a494640db31a44d6ceb24911dce5 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Tue, 21 Feb 2012 04:29:25 +0000 Subject: Report read error if both "genid" and "docid" IDs are found in the same document, to prevent silent merging of distinct blank nodes. git-svn-id: http://svn.drobilla.net/serd/trunk@320 490d8e77-9747-427b-9fa3-0b8f29cee8a0 --- src/reader.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/reader.c b/src/reader.c index 0a6b3467..05dcdfca 100644 --- a/src/reader.c +++ b/src/reader.c @@ -81,6 +81,7 @@ struct SerdReaderImpl { int32_t read_head; ///< Offset into read_buf bool from_file; ///< True iff reading from @ref fd bool eof; + bool seen_genid; #ifdef SERD_STACK_CHECK Ref* allocs; ///< Stack of push offsets size_t n_allocs; ///< Number of stack pushes @@ -948,11 +949,16 @@ read_nodeID(SerdReader* reader) if (!read_name(reader, ref)) { return error(reader, "illegal character at start of name\n"); } - SerdNode* const node = deref(reader, ref); - if (reader->syntax == SERD_TURTLE - && !strncmp((const char*)node->buf, "genid", 5)) { - // Replace "genid" nodes with "docid" to prevent clashing - memcpy((uint8_t*)node + sizeof(SerdNode), "docid", 5); + if (reader->syntax == SERD_TURTLE) { + const char* const buf = (const char*)deref(reader, ref)->buf; + if (!strncmp(buf, "genid", 5)) { + memcpy((char*)buf, "docid", 5); // Prevent clash + reader->seen_genid = true; + } else if (reader->seen_genid && !strncmp(buf, "docid", 5)) { + error(reader, "found both `genid' and `docid' blank IDs\n"); + error(reader, "resolve this with a blank ID prefix\n"); + return pop_node(reader, ref); + } } return ref; } @@ -983,8 +989,7 @@ read_blank(SerdReader* reader, ReadContext ctx, bool subject, Ref* dest) const SerdStatementFlags old_flags = *ctx.flags; switch (peek_byte(reader)) { case '_': - *dest = read_nodeID(reader); - return true; + return (*dest = read_nodeID(reader)); case '[': eat_byte_safe(reader, '['); const bool empty = peek_delim(reader, ']'); @@ -1354,6 +1359,7 @@ serd_reader_new(SerdSyntax syntax, me->read_buf = 0; me->read_head = 0; me->eof = false; + me->seen_genid = false; #ifdef SERD_STACK_CHECK me->allocs = 0; me->n_allocs = 0; -- cgit v1.2.1