From 81ec829b96a01ef08b9fa6191c603c2a4d856c2c Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 5 Oct 2022 09:12:25 +0200 Subject: Fix bug in pdjson.c --- libbutl/json/pdjson.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'libbutl') diff --git a/libbutl/json/pdjson.c b/libbutl/json/pdjson.c index 279d169..0db9a20 100644 --- a/libbutl/json/pdjson.c +++ b/libbutl/json/pdjson.c @@ -472,11 +472,14 @@ read_utf8(json_stream* json, int next_char) int i; for (i = 1; i < count; ++i) { - if ((buffer[i] = json->source.get(&json->source)) != EOF) - json->lineadj++; + if ((next_char = json->source.get(&json->source)) == EOF) + break; + + buffer[i] = next_char; + json->lineadj++; } - if (!is_legal_utf8((unsigned char*) buffer, count)) + if (i != count || !is_legal_utf8((unsigned char*) buffer, count)) { json_error(json, "%s", "invalid UTF-8 text"); return -1; -- cgit v1.1