commit 1c1b63aae786967cef71336d05c247e67b59d9c6
parent 0f5e8266cd624910fc8bdd18de58a42edb28cb5d
Author: James Prestwood <prestwoj@gmail.com>
Date: Fri, 10 Dec 2021 16:13:07 -0800
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
Diffstat:
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git 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);
}