diff options
author | Serge Zaitsev <devnull@localhost> | 2010-12-26 13:48:13 +0200 |
---|---|---|
committer | Serge Zaitsev <devnull@localhost> | 2010-12-26 13:48:13 +0200 |
commit | 4e29ee705f1db5cf2cfed613439a5e8b377f06d9 (patch) | |
tree | 422d1b7f5ba1ee8a9b4c1db3ea5d259cf8a4eda2 | |
parent | 99247345750f32468ce163e3c8a0ac39b52c65f0 (diff) |
Fix: check if no tokens lefs, return error in that case
-rw-r--r-- | jsmn.c | 6 |
1 files changed, 6 insertions, 0 deletions
@@ -49,6 +49,8 @@ static int jsmn_parse_primitive(jsmn_parser *parser) { case '\t' : case '\r' : case '\n' : case ' ' : case ',' : case ']' : case '}' : token = jsmn_get_token(parser); + if (token == NULL) + return JSMN_ERROR_NOMEM; jsmn_fill_token(token, JSON_PRIMITIVE, start, parser->pos); parser->pos--; return JSMN_SUCCESS; @@ -79,6 +81,8 @@ static int jsmn_parse_string(jsmn_parser *parser) { /* Quote: end of string */ if (c == '\"') { token = jsmn_get_token(parser); + if (token == NULL) + return JSMN_ERROR_NOMEM; jsmn_fill_token(token, JSON_PRIMITIVE, start+1, parser->pos); return JSMN_SUCCESS; } @@ -121,6 +125,8 @@ jsmnerr_t jsmn_parse(jsmn_parser *parser) { switch (c) { case '{': case '[': token = jsmn_get_token(parser); + if (token == NULL) + return JSMN_ERROR_NOMEM; token->type = (c == '{' ? JSON_OBJECT : JSON_ARRAY); token->start = parser->pos; break; |