Support negative fixnums in input, and perform some extra validation.
This commit is contained in:
parent
449b0cf478
commit
439491a80e
13
reader.c
13
reader.c
|
|
@ -74,6 +74,7 @@ static value_t read_one_value(reader_state_t *state)
|
|||
return read_special(state);
|
||||
case '(':
|
||||
return read_list(state);
|
||||
case '-':
|
||||
case '0' ... '9':
|
||||
return read_number(state);
|
||||
case '\"':
|
||||
|
|
@ -218,6 +219,14 @@ static value_t read_list(reader_state_t *state)
|
|||
static value_t read_number(reader_state_t *state)
|
||||
{
|
||||
fixnum_t num = 0;
|
||||
bool negative = false;
|
||||
|
||||
if (state->ch == '-')
|
||||
{
|
||||
negative = true;
|
||||
next_char(state);
|
||||
release_assert(isdigit(state->ch));
|
||||
}
|
||||
|
||||
while (isdigit(state->ch))
|
||||
{
|
||||
|
|
@ -227,6 +236,10 @@ static value_t read_number(reader_state_t *state)
|
|||
next_char(state);
|
||||
}
|
||||
|
||||
if (negative)
|
||||
num = -num;
|
||||
|
||||
release_assert((FIXNUM_MIN <= num) && (num <= FIXNUM_MAX));
|
||||
return fixnum_value(num);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue