Commit Graph
1533 Commits
Author SHA1 Message Date
Eric Hawicz cbc3d2c71d Merge pull request #976 from sswamy48/AIX_memleak
AIX:Fix memory leak in json_tokener_parse_ex due to duplocale
2026-10-25 17:49:44 -04:00
Eric Hawicz 174d76e74e Merge pull request #986 from anon5376/codex/tokener-reset-surrogate
tokener: clear pending surrogate on reset
2026-10-25 12:02:52 -04:00
Eric Hawicz 2403a84276 Merge pull request #988 from aokblast/fix-lld-symbol
meson: Fix lld version script detection
2026-10-21 06:56:05 -04:00
ShengYi Hung de70fe69fd meson: Fix lld version script detection
In lld, a symbol version with undefined symbol is rejected by
default. In previous CMake, we use a wildcard for all symbol, which is
fine for empty program. Add --undefined-version to the detection to
fix it.
2026-10-20 23:28:40 -05:00
qeqx 7662139501 tokener: clear pending surrogate on reset
Discard the previous document's high surrogate when resetting the tokener.
Otherwise the next Unicode escape can add a replacement character or
combine with a surrogate from the abandoned document.

Extend the existing incremental parse tests for incomplete input and a
fatal error, using independent next-document string expectations.

Fixes #984.
Reported-by: GeekQAQ (GitHub)
Assisted-by: OpenAI Codex (AI)
Reviewed-by: GPT-6 Luna (AI)
2026-10-10 20:06:11 +09:00
Sangamesh Mallayya fd92d58f2d Fix memory leak in json_tokener_parse_ex due to duplocale
json-c uses duplocale+newlocale+uselocale() to temporarily switch LC_NUMERIC
to "C" during JSON number parsing.

On AIX, every call to json_tokener_parse_ex permanently leaks memory.
This was confirmed with dbx malloc allocation.

0x20008af8           24    0     YORKTOWN
0x20008e18         5128    0     YORKTOWN
0x2000a458          776    0     YORKTOWN
0x2000a768          776    0     YORKTOWN
0x2000aa78          776    0     YORKTOWN
0x2000ad88          776    0     YORKTOWN
0x2000b098          776    0     YORKTOWN
0x2000b6b8          776    0     YORKTOWN

dbx malloc allocation showing new allocations surviving after each parse call with ~776
bytes left after invocations.

The root cause is that on AIX, locale category objects allocated by duplocale() are not
released back to the process heap, even when freelocale() is called correctly.
This causes unbounded heap growth in any long-running process that parses JSON repeatedly.

The fix it to replace the per-call duplocale+newlocale+reelocale() with a single
file-scope static locale_t created once on first call using
newlocale(LC_NUMERIC_MASK, "C", (locale_t)0) and reused for the lifetime of the library.
This reduces newlocale calls on all platforms.

__attribute__((destructor)) function json_tokener_locale_fini() frees the static locale
when the library is unloaded via dlclose() or process exit.
2026-10-08 01:37:47 -05:00
Eric Hawicz 9e99c1cfe7 Merge pull request #975 from afonsojanu/fix/patch-move-copy-sibling-prefix
json_patch: fix move/copy false rejection between sibling keys sharing a prefix
2026-10-04 17:37:56 -04:00
Eric Hawicz dcd1572e60 Merge pull request #978 from ManoharPaturi/fix-array-shrink-type-check
Assert the object type in json_object_array_shrink like every array accessor
2026-09-30 20:19:03 -04:00
Eric Hawicz 1ed5e6fef2 Merge pull request #977 from Expertcoderz/master
Fix header installation path in CMakeLists
2026-09-30 19:52:42 -04:00
Eric Hawicz ceeff4b9d2 Merge pull request #974 from sswamy48/AIX_null
AIX: Fix test_json_patch NULL pointer passed to printf
2026-09-30 19:13:20 -04:00
Eric Hawicz 645e768933 Merge pull request #979 from ManoharPaturi/fix-escape-str-append-errors
Propagate printbuf append failures in json_escape_str
2026-09-30 19:06:40 -04:00
Eric Hawicz b469bea36e Merge pull request #980 from ManoharPaturi/fix-printbuf-memset-nul
printbuf_memset: maintain the NUL-termination invariant
2026-09-29 19:31:39 -04:00
Manohar Paturi b5cd62dcad printbuf_memset: maintain the NUL-termination invariant 2026-09-29 21:36:10 +05:30
Manohar Paturi 353e643768 Propagate printbuf append failures in json_escape_str 2026-09-29 21:35:52 +05:30
Manohar Paturi 168c0f320a Assert the object type in json_object_array_shrink like every array accessor 2026-09-29 21:33:38 +05:30
Expertcoderz e32fe9b410 Fix header installation path in CMakeLists 2026-09-29 15:15:14 +00:00
Afonso Januário 1b504e26ab json_patch: fix move/copy false rejection between sibling keys sharing a prefix
json_patch_apply_move_copy() checks that "from" is not a proper prefix
of "path" per RFC 6902 section 4.4 (a location cannot be moved into one
of its own children), but it did so with a plain strncmp() over the raw
pointer strings, without checking that the shared run of characters
actually ends on a JSON Pointer reference-token boundary in "path".

As a result, moving or copying between two sibling object keys where
one name is a textual prefix of the other, e.g. "/aa" to "/aab", was
rejected with "Invalid attempt to move parent under a child" even
though "/aa" is not an ancestor pointer of "/aab" at all, just an
unrelated key that happens to share a few leading characters.

The fix requires that the character in "path" right after the shared
"from" prefix be either the end of the string (equal paths, a no-op)
or a '/' (a genuine nested reference token), before treating it as an
attempt to move a location under its own descendant.

Added two cases to json_patch_tests.json covering the move and copy
operations between such sibling keys, and refreshed the corresponding
golden test_json_patch.expected output.
2026-09-25 23:52:49 +01:00
Sangamesh Mallayya 52f57ec18a AIX: Fix test_json_patch NULL pointer passed to printf
Some test_json_patch test cases have neither a comment field and
nor a error field, so the expression
"comment ? comment : error_s"  evaluates to NULL.

The printf statement

printf("Testing '%s', ...", comment ? comment : error_s, ...);

passes NULL as a %s argument. GNU libc handles this gracefully and prints (null).
On AIX, passing NULL for %s prints an empty string, causing the test output
to differ from the expected file.

The fix adds a simple macro:

define STR_OR_NULL(s) ((s) ? (s) : "(null)")

that retruns "(null)" when s is NULL.
2026-09-21 01:03:16 -05:00
Eric Hawicz 25895a587e Instead of hardcoding the version into amiga/json-c.readme, generate it on the fly from either a release tag or a development version + commit hash. 2026-09-20 16:06:05 -04:00
Eric Hawicz 19980dbafd Merge pull request #963 from sacredbanana/fbaserel
Amiga enhancements: Build for more platforms + package for Aminet
2026-09-20 16:02:19 -04:00
Eric Hawicz fa774da301 Merge pull request #968 from 1234binpig/master
json_parse: report incomplete and failed input
2026-09-19 20:12:00 -04:00
Eric Hawicz a559871165 Merge pull request #971 from prownd/json_tokener-arraylist-assorted-cleanups-s01
json_tokener, arraylist: assorted cleanups
2026-09-14 23:14:06 -04:00
huangwenbin 0e5a2d43f7 json_parse returned success when input ended while the tokener was
still waiting for more data, and also after read() failures.

Finalize the tokener at EOF with the terminating NUL so valid scalar
values can complete, while rejecting genuinely truncated input.

Also propagate read errors to the caller and add CLI regression tests.
2026-09-14 15:23:04 +08:00
hanjinpeng 596c9d2d03 json_tokener, arraylist: assorted cleanups
json_tokener.c assigned to an int64_t through a (uint64_t) cast.  The
guarded range makes it harmless, but the cast names the wrong type.

array_list_expand_internal() reallocated when max == arr->size even though
the array can already hold max entries at that point, since callers only
index up to max - 1.  Skip the realloc.
2026-09-13 23:08:18 -04:00
Eric Hawicz a954bda619 Merge pull request #969 from hilbert149/docs
Documentation fixes
2026-09-12 09:40:11 -04:00
Eric Hawicz 694b912496 Merge pull request #970 from hilbert149/parseit
json_parse: Exit with error when reading the input fails
2026-09-12 09:39:00 -04:00
panzhe ea23279b75 json_parse: Exit with error when reading the input fails 2026-09-09 11:52:42 +08:00
panzhe 0dd8a021d7 Documentation fixes 2026-09-09 11:22:11 +08:00
Eric Hawicz 8381d33d78 Merge pull request #967 from hilbert149/exit_with_error
Fix json_parse:exit with error when input file cannot be opened
2026-09-07 07:56:02 -05:00
Eric Hawicz 18000a8e5a Merge pull request #966 from hilbert149/json_object_array_to_json_string
json_object_array_to_json_string: Hoist array length out of the loop
2026-09-07 07:55:03 -05:00
panzhe b11a9cd5fe json_object_array_to_json_string: Hoist array length out of the loop
json_object_array_length() was re-evaluated on every iteration.
Move it out of the loop to align with json_object_deep_copy_recursive().
2026-09-07 15:23:26 +08:00
panzhe 6c57831f03 Fix json_parse:exit with error when input file cannot be opened 2026-09-07 15:15:32 +08:00
Eric Hawicz 7760bce042 Merge pull request #965 from hilbert149/lseek-args
Fix swapped lseek() arguments
2026-09-06 22:51:47 -04:00
panzhe 5815babc4f Fix swapped lseek() arguments
lseek() expects (fd, offset, whence). The test passed (fd, SEEK_SET, 0),
which does not conform to the function signature. It should be corrected
to (fd, 0, SEEK_SET).
2026-09-07 09:58:09 +08:00
Eric Hawicz a0bfde7d02 Merge pull request #964 from hilbert149/master
Fix typo in json_object_iterator.h
2026-09-02 06:44:36 -04:00
panzhe 0fbd6ae464 Fix typo in json_object_iterator.h 2026-09-02 17:21:36 +08:00
Cameron Armstrong (Nightfox)andCursor 083d244d9a Address review feedback on the Amiga packaging PR.
Keep Amiga-specific files under amiga/, cache the pinned LHa binary in
CI, and make it explicit that the workflow artifact is not an official
release.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-30 23:28:43 +08:00
Eric Hawicz befb5a0b26 Merge pull request #961 from dxbjavid/pointer-set-unescape
decode ~1/~0 escapes when setting an object member in json_pointer
2026-08-30 10:22:42 -04:00
Eric Hawicz 697c6bfeb5 Merge pull request #962 from junkilee80/fix/object-add-key-leak
Fix object key leak on insertion failure
2026-08-30 10:20:29 -04:00
Cameron Armstrong (Nightfox) 385c46ef39 Add Amiga workflow 2026-08-24 03:14:08 +08:00
Cameron Armstrong (Nightfox) 6a273c567b add json-c directory to root of lha 2026-08-24 02:28:34 +08:00
Cameron Armstrong (Nightfox) 13778a9cb6 Update readme 2026-08-24 02:22:13 +08:00
Cameron Armstrong (Nightfox) 3ea3271978 Package for Amiga for publishing 2026-08-23 22:19:43 +08:00
Cameron Armstrong (Nightfox) a52110770c Update readme 2026-08-23 04:42:40 +08:00
Cameron Armstrong (Nightfox) f6881669c2 Specify fbaserel and Motorola CPU target 2026-08-22 14:47:19 +08:00
Javid Khan dcdea4e906 decode ~1/~0 escapes when setting an object member in json_pointer 2026-08-22 12:01:01 +05:30
Junki Lee 2094974201 Fix object key leak on insertion failure 2026-08-21 13:18:26 +09:00
Eric Hawicz d17ad9d186 Merge pull request #960 from Max13245/fix/test-json-parse-cli
Fix test_json_parse_cli
2026-08-20 21:27:31 -04:00
Max Rijkers 105a1067e3 Use printf instead of echo 2026-08-20 23:21:16 +02:00
Max Rijkers c80ca19a35 Only execute test_json_parse_cli when BUILD_APPS is ON 2026-08-20 23:19:38 +02:00