From: Eric Hawicz Date: Sun, 21 Jun 2026 16:43:20 +0000 (-0400) Subject: Issue #929: fix bad calculation of error offset when parsing in the apps/json_parse... X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1d658982e591389341a92aae2ee54cd26e81beb5;p=thirdparty%2Fjson-c.git Issue #929: fix bad calculation of error offset when parsing in the apps/json_parse tool. Also, show the failing character in hex to ensure error output is readable. --- diff --git a/apps/json_parse.c b/apps/json_parse.c index 3f8ef00..f797d27 100644 --- a/apps/json_parse.c +++ b/apps/json_parse.c @@ -111,12 +111,12 @@ static int parseit(int fd, int (*callback)(struct json_object *)) size_t parse_end = json_tokener_get_parse_end(tok); if (obj == NULL && jerr != json_tokener_continue) { - const char *aterr = (start_pos + parse_end < (int)sizeof(buf)) ? + const char *aterr = (start_pos + parse_end < retu) ? &buf[start_pos + parse_end] : ""; fflush(stdout); size_t fail_offset = total_read - retu + start_pos + parse_end; - fprintf(stderr, "Failed at offset %lu: %s %c\n", (unsigned long)fail_offset, - json_tokener_error_desc(jerr), aterr[0]); + fprintf(stderr, "Failed at offset %lu: %s: char=0x%02x\n", (unsigned long)fail_offset, + json_tokener_error_desc(jerr), (unsigned char)aterr[0]); json_tokener_free(tok); return 1; }