mirror of
https://github.com/json-c/json-c.git
synced 2026-09-08 00:56:50 +08:00
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.
This commit is contained in:
+3
-3
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user