From 6dd02a5d6e421e2cbe901de8103e5f2dab38ade7 Mon Sep 17 00:00:00 2001 From: Jesse McDonald Date: Mon, 12 Apr 2010 14:08:34 -0500 Subject: [PATCH] Stop reading at EOF, and signal an error when EOF occurs inside a string. --- reader.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/reader.c b/reader.c index 8a5e8b3..6d83803 100644 --- a/reader.c +++ b/reader.c @@ -489,6 +489,8 @@ static value_t read_string(reader_state_t *state) bool skip_ws = false; char ch; + release_assert(state->ch != EOF); + if ((buffer_size - length) < 1) { release_assert(buffer_size <= INT32_MAX / 3); @@ -551,7 +553,10 @@ static value_t read_string(reader_state_t *state) /* Treats everything that follows on the same line as a comment, * and additionally skips leading whitespace on the next line. */ while (state->ch != '\n') + { + release_assert(state->ch != EOF); next_char(state); + } skip_ws = true; break; case '\\': ch = '\\'; next_char(state); break; @@ -870,16 +875,19 @@ static void tree_replace(value_t *in, value_t oldval, value_t newval) static void next_char(reader_state_t *state) { - state->ch = fgetc(state->file); + if (state->ch != EOF) + { + state->ch = fgetc(state->file); - if (state->ch == '\n') - { - ++state->line; - state->column = 0; - } - else - { - ++state->column; + if (state->ch == '\n') + { + ++state->line; + state->column = 0; + } + else + { + ++state->column; + } } }