From 1c1b63aae786967cef71336d05c247e67b59d9c6 Mon Sep 17 00:00:00 2001 From: James Prestwood Date: Fri, 10 Dec 2021 16:13:07 -0800 Subject: [PATCH] json: fix pointer arithmetic error Subtracting the pointers is sufficient for counting the tokens, they do not need to be modulus the size of jsmntok_t --- src/json.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/json.c b/src/json.c index 20adcec7..39570e7e 100644 --- a/src/json.c +++ b/src/json.c @@ -82,7 +82,7 @@ static int find_object_tokens(struct json_iter *iter, jsmntok_t *object) if (!next) next = ITER_END(iter); - return ((next - object) % sizeof(jsmntok_t)) - 1; + return next - object - 1; } static void iter_recurse(struct json_iter *iter, jsmntok_t *object, @@ -91,7 +91,7 @@ static void iter_recurse(struct json_iter *iter, jsmntok_t *object, struct json_contents *c = iter->contents; child->contents = c; - child->start = (object - c->tokens) % sizeof(jsmntok_t); + child->start = object - c->tokens; child->count = find_object_tokens(iter, object); }