Skip to content

Commit

Permalink
Merge pull request #1021 from xexyl/util
Browse files Browse the repository at this point in the history
  • Loading branch information
lcn2 authored Nov 8, 2024
2 parents 053ae3f + b3b9164 commit 747947d
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 36 deletions.
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
23 changes: 23 additions & 0 deletions jparse/CHANGES.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

Expand Down
67 changes: 39 additions & 28 deletions jparse/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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, '<', '>');
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -3619,31 +3630,31 @@ 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) */

/* 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 */
Expand All @@ -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 */
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
}
Expand Down
6 changes: 3 additions & 3 deletions jparse/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
8 changes: 4 additions & 4 deletions soup/oebxergfB.h
Original file line number Diff line number Diff line change
Expand Up @@ -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. :-)
Expand Down
2 changes: 1 addition & 1 deletion soup/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */


/*
Expand Down

0 comments on commit 747947d

Please sign in to comment.