3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-12-22 04:32:37 +01:00

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
This commit is contained in:
James Prestwood 2021-12-10 16:13:07 -08:00 committed by Denis Kenzior
parent 0f5e8266cd
commit 1c1b63aae7

View File

@ -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);
}