]> git.ipfire.org Git - thirdparty/json-c.git/commitdiff
Issue #929: fix bad calculation of error offset when parsing in the apps/json_parse...
authorEric Hawicz <erh+git@nimenees.com>
Sun, 21 Jun 2026 16:43:20 +0000 (12:43 -0400)
committerEric Hawicz <erh+git@nimenees.com>
Sun, 21 Jun 2026 16:43:20 +0000 (12:43 -0400)
Also, show the failing character in hex to ensure error output is readable.

apps/json_parse.c

index 3f8ef00339216c0ff4b806f362a5acec1afdc72b..f797d273f639f9f14cf91fa760079b7f4b1b1171 100644 (file)
@@ -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;
                        }