From 7ef9b2dc1dfaefa32b3817e2aa0f18b8eac56cf7 Mon Sep 17 00:00:00 2001 From: Igor Burago Date: Fri, 22 Sep 2023 14:50:43 +0800 Subject: [PATCH 1/2] json: Fix a disjointed update of a token's pointer and length in json_deq() --- json.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/json.h b/json.h index 15c34ce..dde9bce 100644 --- a/json.h +++ b/json.h @@ -701,7 +701,7 @@ json_deq(struct json_token *tok) { /* dequotes a string token */ if (tok->str[0] == '\"' && tok->len >= 2) - tok->str++; tok->len-=2; + tok->str++, tok->len-=2; } JSON_INTERN json_number json_ipow(int base, unsigned exp) From 5b9e9d9027343b44535b42f53e83ad97e4c53ea0 Mon Sep 17 00:00:00 2001 From: Igor Burago Date: Fri, 22 Sep 2023 14:57:26 +0800 Subject: [PATCH 2/2] json: Combine one-line joint index or pointer updates into single statements When a pointer-index pair is jointly updated on a single line, it is sometimes kept as two separate statements and sometimes melded into one. Since the whole point of making said updates one-liners is to highlight their paired nature, let us make it clear in a consistent way and always use a single statement in such cases. --- json.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/json.h b/json.h index dde9bce..95d2295 100644 --- a/json.h +++ b/json.h @@ -851,7 +851,7 @@ JSON_API struct json_iter json_begin(const char *str, int len) { struct json_iter iter = JSON_ITER_NULL; - iter.src = str; iter.len = len; + iter.src = str, iter.len = len; return iter; } JSON_API struct json_iter @@ -958,7 +958,7 @@ json_read(struct json_token *obj, const struct json_iter* prev) iter.src = cur; iter.len = len; return iter; - } cur--; len++; + } cur--, len++; } break; case JSON_STATE_UTF8_2: { iter.go = json_go_utf8; @@ -1230,7 +1230,7 @@ json_query(struct json_token *toks, int count, const char *path) array.len = 0; /* iterate over each array element and find the correct index */ - iter++; i++; + iter++, i++; for (j = 0; j < n; ++j) { if (iter->type == JSON_ARRAY || iter->type == JSON_OBJECT) { i = i + (iter->sub) + 1;