diff --git a/jsmn.h b/jsmn.h index a6772ca6..9f538fed 100644 --- a/jsmn.h +++ b/jsmn.h @@ -315,26 +315,34 @@ static int jsmn_parse_primitive(jsmn_parser *parser, const char *js, numstate != JSMN_NUM_INT_ZERO && numstate != JSMN_NUM_FRAC && numstate != JSMN_NUM_EXP) { - return JSMN_ERROR_INVAL; + if (parser->pos >= len || js[parser->pos] == '\0') { + parser->pos = start; + return JSMN_ERROR_PART; + } else { + return JSMN_ERROR_INVAL; + } } } /* Verify that what comes after the primitive is a non-primitive character */ - switch (js[parser->pos]) { - case '\t': - case '\r': - case '\n': - case ' ': - case ',': - case ':': - case '"': - case '[': - case ']': - case '{': - case '}': - break; - default: - return JSMN_ERROR_INVAL; + if (parser->pos < len) { + switch (js[parser->pos]) { + case '\t': + case '\r': + case '\n': + case ' ': + case ',': + case ':': + case '"': + case '[': + case ']': + case '{': + case '}': + case '\0': + break; + default: + return JSMN_ERROR_INVAL; + } } #else for (; parser->pos < len && js[parser->pos] != '\0'; parser->pos++) { @@ -387,12 +395,11 @@ static int jsmn_parse_string(jsmn_parser *parser, const char *js, const size_t len, jsmntok_t *tokens, const size_t num_tokens) { jsmntok_t *token; - unsigned int start = parser->pos; + /* Skip starting quote */ parser->pos++; - /* Skip starting quote */ for (; parser->pos < len && js[parser->pos] != '\0'; parser->pos++) { char c = js[parser->pos];