From a230bac3a01365911acb89312a21ce186be6efe1 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 12 Dec 2011 02:44:39 +0000 Subject: Remove branch for EOF detection in eat_byte. git-svn-id: http://svn.drobilla.net/serd/trunk@251 490d8e77-9747-427b-9fa3-0b8f29cee8a0 --- src/reader.c | 13 ++++--------- src/serdi.c | 2 +- tests/bad-eof-in-blank.ttl | 3 +++ tests/bad-eof-in-list.ttl | 3 +++ tests/bad-eof-in-string.ttl | 3 +++ tests/bad-eof-in-uri.ttl | 3 +++ wscript | 1 - 7 files changed, 17 insertions(+), 11 deletions(-) create mode 100644 tests/bad-eof-in-blank.ttl create mode 100644 tests/bad-eof-in-list.ttl create mode 100644 tests/bad-eof-in-string.ttl create mode 100644 tests/bad-eof-in-uri.ttl diff --git a/src/reader.c b/src/reader.c index c1c2a1bd..4424c61c 100644 --- a/src/reader.c +++ b/src/reader.c @@ -158,6 +158,7 @@ eat_byte(SerdReader* reader, const uint8_t byte) const uint8_t c = peek_byte(reader); ++reader->read_head; switch (c) { + case '\0': reader->eof = true; break; case '\n': ++reader->cur.line; reader->cur.col = 0; break; default: ++reader->cur.col; } @@ -169,9 +170,6 @@ eat_byte(SerdReader* reader, const uint8_t byte) TRY_RET(page(reader)); assert(reader->read_head < SERD_PAGE_SIZE); } - if (reader->read_buf[reader->read_head] == '\0') { - reader->eof = true; - } return c; } @@ -1204,9 +1202,6 @@ read_objectList(SerdReader* reader, ReadContext ctx, bool blank) static bool read_predicateObjectList(SerdReader* reader, ReadContext ctx, bool blank) { - if (reader->eof) { - return false; - } Ref predicate = 0; TRY_RET(read_verb(reader, &predicate)); TRY_THROW(read_ws_plus(reader)); @@ -1394,10 +1389,10 @@ read_statement(SerdReader* reader) SerdStatementFlags flags = 0; ReadContext ctx = { 0, 0, 0, &flags }; read_ws_star(reader); - if (reader->eof) { - return true; - } switch (peek_byte(reader)) { + case '\0': + reader->eof = true; + return true; case '@': TRY_RET(read_directive(reader)); break; diff --git a/src/serdi.c b/src/serdi.c index 6020a271..c5183008 100644 --- a/src/serdi.c +++ b/src/serdi.c @@ -155,7 +155,7 @@ main(int argc, char** argv) if (from_file) { in_name = in_name ? in_name : input; if (!in_fd) { - input = serd_uri_to_path(input); + input = serd_uri_to_path(in_name); if (!(in_fd = serd_fopen((const char*)input, "r"))) { return 1; } diff --git a/tests/bad-eof-in-blank.ttl b/tests/bad-eof-in-blank.ttl new file mode 100644 index 00000000..08c13ae9 --- /dev/null +++ b/tests/bad-eof-in-blank.ttl @@ -0,0 +1,3 @@ +@prefix eg: . + +<> eg:thing [ eg:comment "Thing" \ No newline at end of file diff --git a/tests/bad-eof-in-list.ttl b/tests/bad-eof-in-list.ttl new file mode 100644 index 00000000..ca6c352f --- /dev/null +++ b/tests/bad-eof-in-list.ttl @@ -0,0 +1,3 @@ +@prefix eg: . + +<> eg:thing ( eg:car eg:cdr \ No newline at end of file diff --git a/tests/bad-eof-in-string.ttl b/tests/bad-eof-in-string.ttl new file mode 100644 index 00000000..d3a1aa55 --- /dev/null +++ b/tests/bad-eof-in-string.ttl @@ -0,0 +1,3 @@ +@prefix eg: . + +<> eg:comment "This is the string that never ends \ No newline at end of file diff --git a/tests/bad-eof-in-uri.ttl b/tests/bad-eof-in-uri.ttl new file mode 100644 index 00000000..9bd2a64d --- /dev/null +++ b/tests/bad-eof-in-uri.ttl @@ -0,0 +1,3 @@ +@prefix eg: . + +<> eg:uri %s' % (srcdir, nul), 'serdi_static file://%s/tests/manifest.ttl > %s' % (srcdir, nul), 'serdi_static %s/tests/UTF-8.ttl > %s' % (srcdir, nul), 'serdi_static -v > %s' % nul, -- cgit v1.2.1