Simplify number reader; eliminates potentially invalid double-ungetc().

This commit is contained in:
Jesse D. McDonald 2009-11-21 23:45:56 -06:00
parent 307ed97b45
commit e18863c3ad
1 changed files with 3 additions and 8 deletions

View File

@ -342,29 +342,24 @@ static value_t read_number(reader_state_t *state)
{ {
case 'X': case 'X':
case 'x': case 'x':
next_char(state);
radix = 16; radix = 16;
next_char(state);
break; break;
case 'B': case 'B':
case 'b': case 'b':
next_char(state);
radix = 2; radix = 2;
next_char(state);
break; break;
case '0' ... '9': case '0' ... '9':
ungetc(state->ch, state->file);
state->ch = '0';
radix = 8; radix = 8;
break; break;
default: default:
ungetc(state->ch, state->file);
state->ch = '0';
radix = 10; radix = 10;
break; break;
} }
if (radix != 8) if (radix != 10)
{ {
/* Make sure we have at least one digit; if octal then the '0' counts instead */
release_assert(isalnum(state->ch)); release_assert(isalnum(state->ch));
release_assert(char_to_digit(state->ch) < radix); release_assert(char_to_digit(state->ch) < radix);
} }