fix hang on incomplete json ident
This commit is contained in:
parent
8a4f45db71
commit
4760ed147e
1 changed files with 15 additions and 14 deletions
|
@ -170,30 +170,31 @@ static bool json_parse_string(tokendata_t *token, const stream_t *stream) {
|
|||
return true;
|
||||
}
|
||||
|
||||
static bool json_parse_ident(token_t *token, const stream_t *stream, char first) {
|
||||
|
||||
char buf[4];
|
||||
buf[3] = '\0';
|
||||
|
||||
if (stream_read(stream, buf, 3) == false)
|
||||
static bool json_ident_assert(const stream_t *stream, const char *rest) {
|
||||
char c;
|
||||
if (stream_read(stream, &c, 1) == false)
|
||||
return false;
|
||||
if (c != *rest)
|
||||
return false;
|
||||
rest += 1;
|
||||
if (*rest == '\0')
|
||||
return true;
|
||||
else
|
||||
return json_ident_assert(stream, rest);
|
||||
}
|
||||
|
||||
if (first == 't' && strcmp(buf, "rue") == 0) {
|
||||
static bool json_parse_ident(token_t *token, const stream_t *stream, char first) {
|
||||
if (first == 't' && json_ident_assert(stream, "true")) {
|
||||
token->type = TOK_BOOL;
|
||||
token->data.b = true;
|
||||
} else if (first == 'f' && strcmp(buf, "als") == 0) {
|
||||
if (stream_read(stream, buf, 1) == false)
|
||||
return false;
|
||||
if (*buf != 'e')
|
||||
return false;
|
||||
} else if (first == 'f' && json_ident_assert(stream, "alse")) {
|
||||
token->type = TOK_BOOL;
|
||||
token->data.b = false;
|
||||
} else if (first == 'n' && strcmp(buf, "ull") == 0) {
|
||||
} else if (first == 'n' && json_ident_assert(stream, "ull")) {
|
||||
token->type = TOK_NULL;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue