aboutsummaryrefslogtreecommitdiff
path: root/src/common/jsonapi.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/jsonapi.c')
-rw-r--r--src/common/jsonapi.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/common/jsonapi.c b/src/common/jsonapi.c
index f1c80933c92..7dad4da65f6 100644
--- a/src/common/jsonapi.c
+++ b/src/common/jsonapi.c
@@ -1982,8 +1982,11 @@ json_lex_string(JsonLexContext *lex)
} while (0)
#define FAIL_AT_CHAR_END(code) \
do { \
- const char *term = s + pg_encoding_mblen(lex->input_encoding, s); \
- lex->token_terminator = (term <= end) ? term : end; \
+ ptrdiff_t remaining = end - s; \
+ int charlen; \
+ charlen = pg_encoding_mblen_or_incomplete(lex->input_encoding, \
+ s, remaining); \
+ lex->token_terminator = (charlen <= remaining) ? s + charlen : end; \
return code; \
} while (0)