diff options
-rw-r--r-- | libbutl/json/pdjson.c | 9 |
1 files changed, 6 insertions, 3 deletions
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; |