summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/common/jsonapi.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/common/jsonapi.c b/src/common/jsonapi.c
index 177f6e7d957..74df1dc5a3c 100644
--- a/src/common/jsonapi.c
+++ b/src/common/jsonapi.c
@@ -686,6 +686,7 @@ static inline JsonParseErrorType
json_lex_string(JsonLexContext *lex)
{
char *s;
+ char *const end = lex->input + lex->input_length;
int len;
int hi_surrogate = -1;
@@ -697,8 +698,8 @@ json_lex_string(JsonLexContext *lex)
} while (0)
#define FAIL_AT_CHAR_END(code) \
do { \
- lex->token_terminator = \
- s + pg_encoding_mblen_bounded(lex->input_encoding, s); \
+ char *term = s + pg_encoding_mblen(lex->input_encoding, s); \
+ lex->token_terminator = (term <= end) ? term : end; \
return code; \
} while (0)