From 2d1f84fd7dcd55907376aa186eb32838538246de Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Sun, 14 Mar 2021 09:28:38 +0100 Subject: [PATCH] json: Move past the end char of a symbol So that we can put a \0 there and continue parsing the rest of the string. This allows us to in-place parse_string. --- spa/include/spa/utils/json.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spa/include/spa/utils/json.h b/spa/include/spa/utils/json.h index 6976235bd..91e1d2700 100644 --- a/spa/include/spa/utils/json.h +++ b/spa/include/spa/utils/json.h @@ -112,7 +112,7 @@ static inline int spa_json_next(struct spa_json * iter, const char **value) iter->state = __STRUCT; if (iter->depth > 0) goto again; - return iter->cur - *value; + return iter->cur++ - *value; } continue; case __STRING: @@ -124,8 +124,7 @@ static inline int spa_json_next(struct spa_json * iter, const char **value) iter->state = __STRUCT; if (iter->depth > 0) continue; - iter->cur++; - return iter->cur - *value; + return ++iter->cur - *value; case 240 ... 247: utf8_remain++; SPA_FALLTHROUGH; @@ -308,7 +307,8 @@ static inline int spa_json_parse_string(const char *val, int len, char *result) { const char *p; if (!spa_json_is_string(val, len)) { - strncpy(result, val, len); + if (result != val) + strncpy(result, val, len); result += len; } else { for (p = val+1; p < val + len; p++) {