aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPetri Lehtinen <petri@digip.org>2009-09-08 16:22:16 +0300
committerPetri Lehtinen <petri@digip.org>2009-09-08 16:41:07 +0300
commit0f62dac6272e30fa33c59ba97d51dafb06bf12ee (patch)
tree82be5fe40d0a05478176481ba691d42d2a7ec25a
parentab2d93b72486eda30e868b226bec5dcd5ec3273e (diff)
downloadjansson-0f62dac6272e30fa33c59ba97d51dafb06bf12ee.zip
jansson-0f62dac6272e30fa33c59ba97d51dafb06bf12ee.tar.gz
jansson-0f62dac6272e30fa33c59ba97d51dafb06bf12ee.tar.bz2
load: Handle EOF correctly
In stream_get(), EOF never got it to stream->buffer and because of this, stream_unget() failed on some situations. This patch makes stream_get() handle EOF just like any other byte. As a "side effect", lex_scan_string() now needs to unget the EOF, or otherwise it ends up in error message on premature end of input.
-rw-r--r--src/load.c7
1 files changed, 2 insertions, 5 deletions
diff --git a/src/load.c b/src/load.c
index 25df182..fc3679d 100644
--- a/src/load.c
+++ b/src/load.c
@@ -134,10 +134,7 @@ static char stream_get(stream_t *stream, json_error_t *error)
c = stream->buffer[0];
- if(c == EOF && stream->eof(stream->data))
- return EOF;
-
- if(c < 0)
+ if(c < 0 && c != EOF)
{
/* multi-byte UTF-8 sequence */
int i, count;
@@ -257,11 +254,11 @@ static void lex_scan_string(lex_t *lex, json_error_t *error)
lex->value.string = NULL;
lex->token = TOKEN_INVALID;
- /* skip the " */
c = lex_get_save(lex, error);
while(c != '"') {
if(c == EOF) {
+ lex_unget_unsave(lex, c);
if(lex_eof(lex))
error_set(error, lex, "premature end of input");
goto out;