summaryrefslogtreecommitdiffstats
path: root/src/jplist.c
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2022-01-25 18:15:46 +0100
committerGravatar Nikias Bassen2022-01-25 18:15:46 +0100
commit31a353b57152e7b44254853520a06568a4a91dce (patch)
tree4fd274a52941455d5984592896bf95a1e76b0a18 /src/jplist.c
parentf3c65feb0e1f4e177a75ba936d0730f7c3f4b076 (diff)
downloadlibplist-31a353b57152e7b44254853520a06568a4a91dce.tar.gz
libplist-31a353b57152e7b44254853520a06568a4a91dce.tar.bz2
jplist: Make sure the jsmn parser tokens are initialized properly
Diffstat (limited to 'src/jplist.c')
-rw-r--r--src/jplist.c9
1 files changed, 6 insertions, 3 deletions
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 @@ PLIST_API int plist_from_json(const char *json, uint32_t length, plist_t * plist
jsmn_parser parser;
jsmn_init(&parser);
int maxtoks = 256;
+ int curtoks = 0;
int r = 0;
jsmntok_t *tokens = NULL;
@@ -666,14 +667,16 @@ PLIST_API int plist_from_json(const char *json, uint32_t length, plist_t * plist
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: