Stop reading at EOF, and signal an error when EOF occurs inside a string.

This commit is contained in:
Jesse D. McDonald 2010-04-12 14:08:34 -05:00
parent 7e5014ab07
commit 6dd02a5d6e
1 changed files with 17 additions and 9 deletions

View File

@ -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;
@ -869,6 +874,8 @@ static void tree_replace(value_t *in, value_t oldval, value_t newval)
}
static void next_char(reader_state_t *state)
{
if (state->ch != EOF)
{
state->ch = fgetc(state->file);
@ -882,6 +889,7 @@ static void next_char(reader_state_t *state)
++state->column;
}
}
}
static void skip_whitespace(reader_state_t *state)
{