Skip to contentSkip to conversation

json: fix pointer arithmetic error

PATCH Applied James Prestwood 2 participants 2 messages Dec 11, 2021

lore
Share & tools
lore

James Prestwood

author
#0 lore raw

PATCH 1/1 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(-)
src/json.c +2 -2
index 20adcec7..39570e7e 100644
@@ -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);
 }
 
Signature · 1 line
2.31.1
Applied
#1 lore raw

Hi James,

Quoted 6 lines · James Prestwood

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(-)

Applied, thanks.

Regards,
-Denis