From b3b91644178ec43e04c2ac9ef405c7e649d92ece Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Fri, 8 Nov 2024 07:19:33 -0800 Subject: [PATCH] Important bug fix in jparse/util.c Synced jparse/ from the jparse repo (https://github.com/xexyl/jparse/). This includes some important bug fixes in a utility function that resulted, in debug output, invalid JSON, plus an incorrect calculation in one case. --- CHANGES.md | 6 +++++ jparse/CHANGES.md | 23 ++++++++++++++++ jparse/util.c | 67 +++++++++++++++++++++++++++-------------------- jparse/version.h | 6 ++--- soup/oebxergfB.h | 8 +++--- soup/version.h | 2 +- 6 files changed, 76 insertions(+), 36 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 523e3b39..d2e60953 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,11 @@ # Major changes to the IOCCC entry toolkit +## Release 1.6.8 2024-11-08 + +Synced `jparse/` from the [jparse repo](https://github.com/xexyl/jparse/). This +includes some important bug fixes in a utility function that resulted, in debug +output, invalid JSON, plus an incorrect calculation in one case. + ## Release 1.6.7 2024-11-07 Synced `jparse/` from the [jparse repo](https://github.com/xexyl/jparse/) to diff --git a/jparse/CHANGES.md b/jparse/CHANGES.md index 20a9d38f..3bf0a0a2 100644 --- a/jparse/CHANGES.md +++ b/jparse/CHANGES.md @@ -1,5 +1,26 @@ # Significant changes in the JSON parser repo +## Release 2.0.5 2024-11-08 + +Important bug fixes in `fprint_line_buf()` in `util.c`, as follows. First, for +example, the text `"\xf0"` is NOT valid JSON but `"\\xf0"` is. However, that +function printed the former, not the latter, and thus if one were to copy paste +the debug output to a file it would be invalid JSON. Second, there was a +miscalculation in the increment of count in one case, possibly due to the +earlier function. + +What prompted this fix is that it was thought that it might be nice to have +debug output print unicode characters (emojis, non-ASCII characters etc.). Now +this might be nice with a new flag for the tools but this means modifying a lot +of functions and might or might not be worth it. What is definitely worth it is +these fixes, however, so that is done for now. If a new option is desired to +print unicode symbols then that can be considered later. + +The `JPARSE_VERSION` was updated to `"1.2.1 2024-11-08"`. + +The `JPARSE_LIBRARY_VERSION` was updated to `"2.0.1 2024-11-08"`. + + ## Release 2.0.4 2024-11-07 Removed `utf8decode()` from `json_utf8.c` as it appears we will not need it @@ -15,6 +36,8 @@ never happen). Updated `JPARSE_UTF8_VERSION` to `"2.0.3 2024-11-07"`. +Further improvements to `jparse_bug_report.sh`. + ## Release 2.0.3 2024-11-05 diff --git a/jparse/util.c b/jparse/util.c index 59b4fa7e..941660f0 100644 --- a/jparse/util.c +++ b/jparse/util.c @@ -3497,9 +3497,15 @@ clearerr_or_fclose(FILE *stream) * escape chars as literal C escape chars (i.e. if a \n was encountered it would * print "\\n" to show that it was a newline), this function will print the * buffer as a single line, possibly enclosed in starting and ending characters. - * Non-ASCII characters, non-printable ASCII characters, \-characters, start and - * end characters (if non-NUL) will all be printed as \x99 where 99 is the hex - * value, or \C where C is a C-style \-character. + * + * Other characters, such as non ASCII characters or certain non-printable + * characters will be printed as \\x99, where 99 is the hex value. In some + * cases, like \n, which is valid JSON, it will be \n, as noted above. An + * example where it is NOT valid JSON, which we will print two '\'s, is '\e', so + * that becomes "\\e" instead. + * + * The above rules are important because without them in place the output would + * be invalid JSON. * * The line printed will be printed as a single line, without a final * newline. @@ -3510,7 +3516,7 @@ clearerr_or_fclose(FILE *stream) * * The stream is flushed before returning. * - * The errno value is restore to its original state before returning. + * The errno value is restored to its original state before returning. * * Examples: * line_len = fprint_line_buf(stderr, buf, len, '<', '>'); @@ -3531,6 +3537,11 @@ clearerr_or_fclose(FILE *stream) * returns: * length of line (even if MULL stream), or * EOF ==> write error or NULL buf + * + * NOTE: this function will NOT print unicode symbols. To do this a new flag + * to not print the \\x99 but just the character. Another option would be to + * print it out by default but since this function is used in debug output it + * seems fitting to not do that by default. */ ssize_t fprint_line_buf(FILE *stream, const void *buf, size_t len, int start, int end) @@ -3594,15 +3605,15 @@ fprint_line_buf(FILE *stream, const void *buf, size_t len, int start, int end) /* print character as \x99 if non-NULL stream to avoid start/end confusion */ if (stream != NULL) { errno = 0; /* clear errno */ - ret = fprintf(stream, "\\x%02x", c); - if (chk_stdio_printf_err(stream, ret) || ret != 2) { + ret = fprintf(stream, "\\\\x%02x", c); + if (chk_stdio_printf_err(stream, ret) || ret != 5) { delayed_errno = errno; success = false; } } - /* count the 4 characters */ - count += 4; + /* count the 5 characters */ + count += 5; /* * case: ASCII character @@ -3619,15 +3630,15 @@ fprint_line_buf(FILE *stream, const void *buf, size_t len, int start, int end) /* print \0 if non-NULL stream */ if (stream != NULL) { errno = 0; /* clear errno */ - ret = fprintf(stream, "\\0"); - if (chk_stdio_printf_err(stream, ret) || ret != 2) { + ret = fprintf(stream, "\\\\0"); + if (chk_stdio_printf_err(stream, ret) || ret != 3) { delayed_errno = errno; success = false; } } - /* count the 2 characters */ - count += 2; + /* count the 3 characters */ + count += 3; break; case '\a': /* alert (beep, bell) */ @@ -3635,15 +3646,15 @@ fprint_line_buf(FILE *stream, const void *buf, size_t len, int start, int end) /* print \a if non-NULL stream */ if (stream != NULL) { errno = 0; /* clear errno */ - ret = fprintf(stream, "\\a"); - if (chk_stdio_printf_err(stream, ret) || ret != 2) { + ret = fprintf(stream, "\\\\a"); + if (chk_stdio_printf_err(stream, ret) || ret != 3) { delayed_errno = errno; success = false; } } - /* count the 2 characters */ - count += 2; + /* count the 3 characters */ + count += 3; break; case '\b': /* backspace */ @@ -3667,15 +3678,15 @@ fprint_line_buf(FILE *stream, const void *buf, size_t len, int start, int end) /* print \e if non-NULL stream */ if (stream != NULL) { errno = 0; /* clear errno */ - ret = fprintf(stream, "\\e"); - if (chk_stdio_printf_err(stream, ret) || ret != 2) { + ret = fprintf(stream, "\\\\e"); + if (chk_stdio_printf_err(stream, ret) || ret != 3) { delayed_errno = errno; success = false; } } - /* count the 2 characters */ - count += 2; + /* count the 3 characters */ + count += 3; break; case '\f': /* form feed page break */ @@ -3747,15 +3758,15 @@ fprint_line_buf(FILE *stream, const void *buf, size_t len, int start, int end) /* print \v if non-NULL stream */ if (stream != NULL) { errno = 0; /* clear errno */ - ret = fprintf(stream, "\\v"); - if (chk_stdio_printf_err(stream, ret) || ret != 2) { + ret = fprintf(stream, "\\\\v"); + if (chk_stdio_printf_err(stream, ret) || ret != 3) { delayed_errno = errno; success = false; } } - /* count the 2 characters */ - count += 2; + /* count the 3 characters */ + count += 3; break; case '\\': /* backslash */ @@ -3802,15 +3813,15 @@ fprint_line_buf(FILE *stream, const void *buf, size_t len, int start, int end) /* print character as \x99 if non-NULL stream */ if (stream != NULL) { errno = 0; /* clear errno */ - ret = fprintf(stream, "\\x%02x", c); - if (chk_stdio_printf_err(stream, ret) || ret != 4) { + ret = fprintf(stream, "\\\\x%02x", c); + if (chk_stdio_printf_err(stream, ret) || ret != 5) { delayed_errno = errno; success = false; } } - /* count the 4 characters */ - count += 4; + /* count the 5 characters */ + count += 5; } break; } diff --git a/jparse/version.h b/jparse/version.h index 4878afc1..6f0631f4 100644 --- a/jparse/version.h +++ b/jparse/version.h @@ -30,17 +30,17 @@ * * NOTE: this should match the latest Release string in CHANGES.md */ -#define JPARSE_REPO_VERSION "2.0.4 2024-11-07" /* format: major.minor YYYY-MM-DD */ +#define JPARSE_REPO_VERSION "2.0.5 2024-11-08" /* format: major.minor YYYY-MM-DD */ /* * official jparse version */ -#define JPARSE_VERSION "1.2.0 2024-10-09" /* format: major.minor YYYY-MM-DD */ +#define JPARSE_VERSION "1.2.1 2024-11-08" /* format: major.minor YYYY-MM-DD */ /* * official JSON parser version */ -#define JPARSE_LIBRARY_VERSION "2.0.0 2024-10-31" /* library version format: major.minor YYYY-MM-DD */ +#define JPARSE_LIBRARY_VERSION "2.0.1 2024-11-08" /* library version format: major.minor YYYY-MM-DD */ #endif /* INCLUDE_JPARSE_VERSION_H */ diff --git a/soup/oebxergfB.h b/soup/oebxergfB.h index 665ad28c..7306a12e 100644 --- a/soup/oebxergfB.h +++ b/soup/oebxergfB.h @@ -40,11 +40,11 @@ * jrql jrt ziuole entries. Cj'u xtqzzc jrqj simple. Vod cis xtqzzc tkwtyj * uiftjrole tzut? Eiz. * - * BTW: If after looking at this file you think Cody is a bit crazy this is more - * than understandable and Cody is quite okay with it. In fact he rather - * relishes the idea! :-) + * BTW: If after looking at this file you think Cody is more than a bit + * eccentric this is more than understandable and Cody is quite okay with it. In + * fact he rather relishes the idea! :-) * - * "Because Cody enjoys being a bit eccentric and he is rather proud of it too!" :-) + * "Because Cody enjoys being eccentric and he is rather proud of it too!" :-) * * "Share and Enjoy!" * -- Sirius Cybernetics Corporation Complaints Division, JSON spec department. :-) diff --git a/soup/version.h b/soup/version.h index 784ee80f..82275d1f 100644 --- a/soup/version.h +++ b/soup/version.h @@ -66,7 +66,7 @@ * * NOTE: This should match the latest Release string in CHANGES.md */ -#define MKIOCCCENTRY_REPO_VERSION "1.6.7 2024-11-07" /* special release format: major.minor.patch YYYY-MM-DD */ +#define MKIOCCCENTRY_REPO_VERSION "1.6.8 2024-11-08" /* special release format: major.minor.patch YYYY-MM-DD */ /*