jplist: Make sure the jsmn parser tokens are initialized properly
diff --git a/src/jplist.c b/src/jplist.c
index 3d3cad2..cb29742 100644
--- a/src/jplist.c
+++ b/src/jplist.c
@@ -657,6 +657,7 @@
jsmn_parser parser;
jsmn_init(&parser);
int maxtoks = 256;
+ int curtoks = 0;
int r = 0;
jsmntok_t *tokens = NULL;
@@ -666,14 +667,16 @@
PLIST_JSON_ERR("%s: Out of memory\n", __func__);
return PLIST_ERR_NO_MEM;
}
- tokens = newtokens;
+ memset((unsigned char*)newtokens + sizeof(jsmntok_t)*curtoks, '\0', sizeof(jsmntok_t)*(maxtoks-curtoks));
+ tokens = newtokens;
+ curtoks = maxtoks;
r = jsmn_parse(&parser, json, length, tokens, maxtoks);
if (r == JSMN_ERROR_NOMEM) {
maxtoks+=16;
continue;
- }
- } while (0);
+ }
+ } while (r == JSMN_ERROR_NOMEM);
switch(r) {
case JSMN_ERROR_NOMEM: