From aedc121ce8a5ef0156ee6cb7e06fcd96457220a0 Mon Sep 17 00:00:00 2001 From: "Serge A. Zaitsev" Date: Sat, 17 Oct 2015 15:14:13 +0200 Subject: [PATCH] added check for null pointer before fixing tokens after parsing is done --- jsmn.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/jsmn.c b/jsmn.c index 74a62d0..2809669 100644 --- a/jsmn.c +++ b/jsmn.c @@ -289,10 +289,12 @@ int jsmn_parse(jsmn_parser *parser, const char *js, size_t len, } } - for (i = parser->toknext - 1; i >= 0; i--) { - /* Unmatched opened object or array */ - if (tokens[i].start != -1 && tokens[i].end == -1) { - return JSMN_ERROR_PART; + if (tokens != NULL) { + for (i = parser->toknext - 1; i >= 0; i--) { + /* Unmatched opened object or array */ + if (tokens[i].start != -1 && tokens[i].end == -1) { + return JSMN_ERROR_PART; + } } }