Script 'mail_helper' called by obssrc Hello community, here is the log from the commit of package libjansson for openSUSE:Factory checked in at 2026-02-07 15:33:06 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/libjansson (Old) and /work/SRC/openSUSE:Factory/.libjansson.new.1670 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "libjansson" Sat Feb 7 15:33:06 2026 rev:16 rq:1331615 version:2.15.0 Changes: -------- --- /work/SRC/openSUSE:Factory/libjansson/libjansson.changes 2025-05-23 14:30:47.893199753 +0200 +++ /work/SRC/openSUSE:Factory/.libjansson.new.1670/libjansson.changes 2026-02-07 15:33:16.144980723 +0100 @@ -1,0 +2,7 @@ +Fri Feb 6 12:06:41 UTC 2026 - Paolo Stivanin <[email protected]> + +- Update to 2.15.0: + * Add support for realloc by adding json_set_alloc_funcs2, json_get_alloc_funcs2 + * Optimize serialization + +------------------------------------------------------------------- Old: ---- jansson-2.14.1.tar.bz2 jansson-2.14.1.tar.bz2.asc New: ---- jansson-2.15.0.tar.bz2 jansson-2.15.0.tar.bz2.asc ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ libjansson.spec ++++++ --- /var/tmp/diff_new_pack.1bUYC3/_old 2026-02-07 15:33:18.445076282 +0100 +++ /var/tmp/diff_new_pack.1bUYC3/_new 2026-02-07 15:33:18.473077444 +0100 @@ -1,7 +1,7 @@ # # spec file for package libjansson # -# Copyright (c) 2025 SUSE LLC +# Copyright (c) 2026 SUSE LLC and contributors # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -18,7 +18,7 @@ %define lname libjansson4 Name: libjansson -Version: 2.14.1 +Version: 2.15.0 Release: 0 Summary: C library for encoding, decoding and manipulating JSON data License: MIT ++++++ jansson-2.14.1.tar.bz2 -> jansson-2.15.0.tar.bz2 ++++++ ++++ 3258 lines of diff (skipped) ++++ retrying with extended exclude list diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 --exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh old/jansson-2.14.1/CHANGES new/jansson-2.15.0/CHANGES --- old/jansson-2.14.1/CHANGES 2025-03-23 13:11:12.000000000 +0100 +++ new/jansson-2.15.0/CHANGES 2026-01-24 21:54:33.000000000 +0100 @@ -1,3 +1,22 @@ +Version 2.15.0 +============== + +Released 2026-01-24 + +* New features: + + - Add support for realloc by adding `json_set_alloc_funcs2`, `json_get_alloc_funcs2` + (@WilhelmWiens in #717) + +* Fixes: + + - Optimize serialization (@WilhelmWiens in #658 and #719) + - Fix docstrings in hashtable.h (@WilhelmWiens in #718) + +* Build + + - Use target-based cmake settings (@Andrew-Au in #692) + Version 2.14.1 ============== @@ -10,10 +29,10 @@ Bruno Haible for the report and help with fixing.) - Use David M. Gay's `dtoa()` algorithm to avoid misprinting issues of real - numbers that are not exactly representable as a `double` (#680). + numbers that are not exactly representable as a ``double`` (#680). - If this is not desirable, use `./configure --disable-dtoa` or `cmake - -DUSE_DTOA=OFF .` + If this is not desirable, use ``./configure --disable-dtoa`` or ``cmake + -DUSE_DTOA=OFF``. * Build: diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 --exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh old/jansson-2.14.1/CMakeLists.txt new/jansson-2.15.0/CMakeLists.txt --- old/jansson-2.14.1/CMakeLists.txt 2025-03-23 13:13:21.000000000 +0100 +++ new/jansson-2.15.0/CMakeLists.txt 2026-01-24 21:54:33.000000000 +0100 @@ -1,4 +1,4 @@ -cmake_minimum_required (VERSION 3.1) +cmake_minimum_required (VERSION 3.10) project(jansson C) # Options @@ -36,10 +36,10 @@ # set (JANSSON_VERSION "2.3.1") # set (JANSSON_SOVERSION 2) -set(JANSSON_DISPLAY_VERSION "2.14.1") +set(JANSSON_DISPLAY_VERSION "2.15.0") # This is what is required to match the same numbers as automake's -set(JANSSON_VERSION "4.14.0") +set(JANSSON_VERSION "4.15.0") set(JANSSON_SOVERSION 4) # for CheckFunctionKeywords @@ -266,18 +266,15 @@ file (COPY ${CMAKE_CURRENT_SOURCE_DIR}/src/jansson.h DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/include/) -add_definitions(-DJANSSON_USING_CMAKE) - # configure the private config file configure_file (${CMAKE_CURRENT_SOURCE_DIR}/cmake/jansson_private_config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/private_include/jansson_private_config.h) -# and tell the source code to include it -add_definitions(-DHAVE_CONFIG_H) - -include_directories (${CMAKE_CURRENT_BINARY_DIR}/include) include_directories (${CMAKE_CURRENT_BINARY_DIR}/private_include) +# Configuration flags will be set on project later once we have defined the target + + # Add the lib sources. file(GLOB JANSSON_SRC src/*.c) if (NOT USE_DTOA) @@ -356,6 +353,20 @@ POSITION_INDEPENDENT_CODE true) endif() + +# Now target jansson is declared, set per-target values + +target_compile_definitions(jansson PUBLIC JANSSON_USING_CMAKE) +target_compile_definitions(jansson PRIVATE HAVE_CONFIG_H) + +target_include_directories(jansson + PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include> + INTERFACE $<INSTALL_INTERFACE:include> +) + +add_library( jansson::jansson ALIAS jansson ) + + if (JANSSON_EXAMPLES) add_executable(simple_parse "${CMAKE_CURRENT_SOURCE_DIR}/examples/simple_parse.c") target_link_libraries(simple_parse jansson) @@ -480,6 +491,7 @@ set(api_tests test_array test_chaos + test_chaos_realloc test_copy test_dump test_dump_callback @@ -499,6 +511,7 @@ # such as secure_malloc and secure_free is doing, so exclude it for now. if (NOT MSVC) list(APPEND api_tests test_memory_funcs) + list(APPEND api_tests test_memory_funcs_realloc) endif() # Helper macro for building and linking a test program. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 --exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh old/jansson-2.14.1/compile new/jansson-2.15.0/compile --- old/jansson-2.14.1/compile 2025-03-23 13:18:45.000000000 +0100 +++ new/jansson-2.15.0/compile 2026-01-24 21:54:57.000000000 +0100 @@ -1,9 +1,9 @@ #! /bin/sh # Wrapper for compilers which do not understand '-c -o'. -scriptversion=2024-06-19.01; # UTC +scriptversion=2025-06-18.21; # UTC -# Copyright (C) 1999-2024 Free Software Foundation, Inc. +# Copyright (C) 1999-2025 Free Software Foundation, Inc. # Written by Tom Tromey <[email protected]>. # # This program is free software; you can redistribute it and/or modify @@ -37,11 +37,11 @@ file_conv= -# func_file_conv build_file lazy +# func_file_conv build_file unneeded_conversions # Convert a $build file to $host form and store it in $file # Currently only supports Windows hosts. If the determined conversion -# type is listed in (the comma separated) LAZY, no conversion will -# take place. +# type is listed in (the comma separated) UNNEEDED_CONVERSIONS, no +# conversion will take place. func_file_conv () { file=$1 @@ -51,9 +51,20 @@ # lazily determine how to convert abs files case `uname -s` in MINGW*) - file_conv=mingw + if test -n "$MSYSTEM" && (cygpath --version) >/dev/null 2>&1; then + # MSYS2 environment. + file_conv=cygwin + else + # Original MinGW environment. + file_conv=mingw + fi ;; - CYGWIN* | MSYS*) + MSYS*) + # Old MSYS environment, or MSYS2 with 32-bit MSYS2 shell. + file_conv=cygwin + ;; + CYGWIN*) + # Cygwin environment. file_conv=cygwin ;; *) @@ -63,12 +74,14 @@ fi case $file_conv/,$2, in *,$file_conv,*) + # This is the optimization mentioned above: + # If UNNEEDED_CONVERSIONS contains $file_conv, don't convert. ;; mingw/*) file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'` ;; - cygwin/* | msys/*) - file=`cygpath -m "$file" || echo "$file"` + cygwin/*) + file=`cygpath -w "$file" || echo "$file"` ;; wine/*) file=`winepath -w "$file" || echo "$file"` @@ -343,9 +356,9 @@ # Local Variables: # mode: shell-script # sh-indentation: 2 -# eval: (add-hook 'before-save-hook 'time-stamp) +# eval: (add-hook 'before-save-hook 'time-stamp nil t) # time-stamp-start: "scriptversion=" -# time-stamp-format: "%:y-%02m-%02d.%02H" +# time-stamp-format: "%Y-%02m-%02d.%02H" # time-stamp-time-zone: "UTC0" # time-stamp-end: "; # UTC" # End: diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 --exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh old/jansson-2.14.1/configure.ac new/jansson-2.15.0/configure.ac --- old/jansson-2.14.1/configure.ac 2025-03-23 13:12:49.000000000 +0100 +++ new/jansson-2.15.0/configure.ac 2026-01-24 21:54:32.000000000 +0100 @@ -1,5 +1,5 @@ AC_PREREQ([2.60]) -AC_INIT([jansson], [2.14.1], [https://github.com/akheron/jansson/issues]) +AC_INIT([jansson], [2.15.0], [https://github.com/akheron/jansson/issues]) AC_CONFIG_AUX_DIR([.]) AM_INIT_AUTOMAKE([1.10 foreign]) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 --exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh old/jansson-2.14.1/doc/apiref.rst new/jansson-2.15.0/doc/apiref.rst --- old/jansson-2.14.1/doc/apiref.rst 2022-08-09 20:56:05.000000000 +0200 +++ new/jansson-2.15.0/doc/apiref.rst 2026-01-24 21:50:09.000000000 +0100 @@ -1088,7 +1088,7 @@ .. versionadded:: 2.11 -.. function:: enum json_error_code json_error_code(const json_error_t *error) +.. c:function:: enum json_error_code json_error_code(const json_error_t *error) Returns the error code embedded in ``error->text``. @@ -1907,7 +1907,7 @@ Custom Memory Allocation ======================== -By default, Jansson uses :func:`malloc()` and :func:`free()` for +By default, Jansson uses :func:`malloc()`, :func:`realloc()` and :func:`free()` for memory allocation. These functions can be overridden if custom behavior is needed. @@ -1918,6 +1918,16 @@ typedef void *(*json_malloc_t)(size_t); +.. type:: json_realloc_t + + A typedef for a function pointer with :func:`realloc()`'s + signature:: + + typedef void *(*json_realloc_t)(void*, size_t); + + + .. versionadded:: 2.15 + .. type:: json_free_t A typedef for a function pointer with :func:`free()`'s @@ -1932,6 +1942,15 @@ Jansson's API functions to ensure that all memory operations use the same functions. +.. function:: void json_set_alloc_funcs2(json_malloc_t malloc_fn, json_relloc_t relloc_fn, json_free_t free_fn) + + Use *malloc_fn* instead of :func:`malloc()`, *realloc_fn* instead of :func:`realloc()` and *free_fn* instead + of :func:`free()`. This function has to be called before any other + Jansson's API functions to ensure that all memory operations use + the same functions. + + .. versionadded:: 2.15 + .. function:: void json_get_alloc_funcs(json_malloc_t *malloc_fn, json_free_t *free_fn) Fetch the current malloc_fn and free_fn used. Either parameter @@ -1939,6 +1958,13 @@ .. versionadded:: 2.8 +.. function:: void json_get_alloc_funcs2(json_malloc_t *malloc_fn, json_realloc_t *realloc_fn, json_free_t *free_fn) + + Fetch the current malloc_fn,realloc_fn and free_fn used. Either parameter + may be NULL. + + .. versionadded:: 2.15 + **Examples:** Circumvent problems with different CRT heaps on Windows by using @@ -1950,6 +1976,12 @@ operations:: json_set_alloc_funcs(GC_malloc, GC_free); + or + json_set_alloc_funcs2(GC_malloc, GC_realloc, GC_free); + + + When realloc is not defined is it emulated using malloc and free. + .. _Boehm's conservative garbage collector: http://www.hboehm.info/gc/ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 --exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh old/jansson-2.14.1/doc/conf.py new/jansson-2.15.0/doc/conf.py --- old/jansson-2.14.1/doc/conf.py 2025-03-23 13:13:02.000000000 +0100 +++ new/jansson-2.15.0/doc/conf.py 2026-01-24 21:54:32.000000000 +0100 @@ -48,7 +48,7 @@ # built documents. # # The short X.Y version. -version = '2.14.1' +version = '2.15.0' # The full version, including alpha/beta/rc tags. release = version @@ -70,6 +70,9 @@ default_role = 'c:func' primary_domain = 'c' +# Suppress warnings about enum and function having the same name (valid in C) +suppress_warnings = ['duplicate_declaration.c'] + # If true, '()' will be appended to :func: etc. cross-reference text. #add_function_parentheses = True diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 --exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh old/jansson-2.14.1/missing new/jansson-2.15.0/missing --- old/jansson-2.14.1/missing 2025-03-23 13:18:45.000000000 +0100 +++ new/jansson-2.15.0/missing 2026-01-24 21:54:57.000000000 +0100 @@ -1,11 +1,11 @@ #! /bin/sh # Common wrapper for a few potentially missing GNU and other programs. -scriptversion=2024-06-07.14; # UTC +scriptversion=2025-06-18.21; # UTC # shellcheck disable=SC2006,SC2268 # we must support pre-POSIX shells -# Copyright (C) 1996-2024 Free Software Foundation, Inc. +# Copyright (C) 1996-2025 Free Software Foundation, Inc. # Originally written by Fran,cois Pinard <[email protected]>, 1996. # This program is free software; you can redistribute it and/or modify @@ -228,9 +228,9 @@ exit $st # Local variables: -# eval: (add-hook 'before-save-hook 'time-stamp) +# eval: (add-hook 'before-save-hook 'time-stamp nil t) # time-stamp-start: "scriptversion=" -# time-stamp-format: "%:y-%02m-%02d.%02H" +# time-stamp-format: "%Y-%02m-%02d.%02H" # time-stamp-time-zone: "UTC0" # time-stamp-end: "; # UTC" # End: diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 --exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh old/jansson-2.14.1/src/Makefile.am new/jansson-2.15.0/src/Makefile.am --- old/jansson-2.14.1/src/Makefile.am 2025-03-23 13:16:44.000000000 +0100 +++ new/jansson-2.15.0/src/Makefile.am 2026-01-24 21:54:33.000000000 +0100 @@ -30,6 +30,6 @@ libjansson_la_LDFLAGS = \ -no-undefined \ -export-symbols-regex '^json_|^jansson_' \ - -version-info 18:1:14 \ + -version-info 19:0:15 \ @JSON_SYMVER_LDFLAGS@ \ @JSON_BSYMBOLIC_LDFLAGS@ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 --exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh old/jansson-2.14.1/src/dump.c new/jansson-2.15.0/src/dump.c --- old/jansson-2.14.1/src/dump.c 2024-03-31 21:03:18.000000000 +0200 +++ new/jansson-2.15.0/src/dump.c 2026-01-22 07:37:04.000000000 +0100 @@ -26,7 +26,7 @@ #define MAX_INTEGER_STR_LENGTH 25 #define MAX_REAL_STR_LENGTH 25 -#define FLAGS_TO_INDENT(f) ((f)&0x1F) +#define FLAGS_TO_INDENT(f) ((f) & 0x1F) #define FLAGS_TO_PRECISION(f) (((f) >> 11) & 0x1F) struct buffer { @@ -283,21 +283,20 @@ if (dump_indent(flags, depth + 1, 0, dump, data)) return -1; - for (i = 0; i < n; ++i) { + for (i = 0; i < n - 1; ++i) { if (do_dump(json_array_get(json, i), flags, depth + 1, parents, dump, data)) return -1; - if (i < n - 1) { - if (dump(",", 1, data) || - dump_indent(flags, depth + 1, 1, dump, data)) - return -1; - } else { - if (dump_indent(flags, depth, 0, dump, data)) - return -1; - } + if (dump(",", 1, data) || dump_indent(flags, depth + 1, 1, dump, data)) + return -1; } + if (do_dump(json_array_get(json, i), flags, depth + 1, parents, dump, data)) + return -1; + if (dump_indent(flags, depth, 0, dump, data)) + return -1; + hashtable_del(parents, key, key_len); return embed ? 0 : dump("]", 1, data); } @@ -322,10 +321,10 @@ &loop_key_len)) return -1; - iter = json_object_iter((json_t *)json); - if (!embed && dump("{", 1, data)) return -1; + + iter = json_object_iter((json_t *)json); if (!iter) { hashtable_del(parents, loop_key, loop_key_len); return embed ? 0 : dump("}", 1, data); @@ -432,8 +431,15 @@ if (json_dump_callback(json, dump_to_strbuffer, (void *)&strbuff, flags)) result = NULL; - else - result = jsonp_strdup(strbuffer_value(&strbuff)); + else { + char *new_result; + result = strbuffer_steal_value(&strbuff); + // technically the resizing is not needed. + new_result = jsonp_realloc(result, strbuff.size, strbuff.length + 1); + if (new_result) { // when realloc fails we just use the original pointer + result = new_result; + } + } strbuffer_close(&strbuff); return result; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 --exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh old/jansson-2.14.1/src/hashtable.c new/jansson-2.15.0/src/hashtable.c --- old/jansson-2.14.1/src/hashtable.c 2024-03-08 20:06:10.000000000 +0100 +++ new/jansson-2.15.0/src/hashtable.c 2026-01-22 07:37:04.000000000 +0100 @@ -154,7 +154,7 @@ hashtable->buckets = new_buckets; hashtable->order = new_order; - for (i = 0; i < hashsize(hashtable->order); i++) { + for (i = 0; i < new_size; i++) { hashtable->buckets[i].first = hashtable->buckets[i].last = &hashtable->list; } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 --exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh old/jansson-2.14.1/src/hashtable.h new/jansson-2.15.0/src/hashtable.h --- old/jansson-2.14.1/src/hashtable.h 2022-08-09 20:56:05.000000000 +0200 +++ new/jansson-2.15.0/src/hashtable.h 2026-01-22 07:37:04.000000000 +0100 @@ -70,12 +70,11 @@ * * @hashtable: The hashtable object * @key: The key - * @key: The length of key - * @serial: For addition order of keys + * @key_len: The length of key * @value: The value * * If a value with the given key already exists, its value is replaced - * with the new value. Value is "stealed" in the sense that hashtable + * with the new value. Value is "stolen" in the sense that hashtable * doesn't increment its refcount but decreases the refcount when the * value is no longer needed. * @@ -88,7 +87,7 @@ * * @hashtable: The hashtable object * @key: The key - * @key: The length of key + * @key_len: The length of key * * Returns value if it is found, or NULL otherwise. */ @@ -99,7 +98,7 @@ * * @hashtable: The hashtable object * @key: The key - * @key: The length of key + * @key_len: The length of key * * Returns 0 on success, or -1 if the key was not found. */ @@ -136,7 +135,7 @@ * * @hashtable: The hashtable object * @key: The key that the iterator should point to - * @key: The length of key + * @key_len: The length of key * * Like hashtable_iter() but returns an iterator pointing to a * specific key. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 --exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh old/jansson-2.14.1/src/jansson.def new/jansson-2.15.0/src/jansson.def --- old/jansson-2.14.1/src/jansson.def 2022-08-09 20:56:05.000000000 +0200 +++ new/jansson-2.15.0/src/jansson.def 2026-01-22 07:37:04.000000000 +0100 @@ -77,7 +77,9 @@ json_unpack_ex json_vunpack_ex json_set_alloc_funcs + json_set_alloc_funcs2 json_get_alloc_funcs + json_get_alloc_funcs2 jansson_version_str jansson_version_cmp diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 --exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh old/jansson-2.14.1/src/jansson.h new/jansson-2.15.0/src/jansson.h --- old/jansson-2.14.1/src/jansson.h 2025-03-23 13:13:41.000000000 +0100 +++ new/jansson-2.15.0/src/jansson.h 2026-01-24 21:54:32.000000000 +0100 @@ -21,11 +21,11 @@ /* version */ #define JANSSON_MAJOR_VERSION 2 -#define JANSSON_MINOR_VERSION 14 -#define JANSSON_MICRO_VERSION 1 +#define JANSSON_MINOR_VERSION 15 +#define JANSSON_MICRO_VERSION 0 /* Micro version is omitted if it's 0 */ -#define JANSSON_VERSION "2.14.1" +#define JANSSON_VERSION "2.15.0" /* Version as a 3-byte hex number, e.g. 0x010201 == 1.2.1. Use this for numeric comparisons, e.g. #if JANSSON_VERSION_HEX >= ... */ @@ -379,14 +379,14 @@ /* encoding */ #define JSON_MAX_INDENT 0x1F -#define JSON_INDENT(n) ((n)&JSON_MAX_INDENT) +#define JSON_INDENT(n) ((n) & JSON_MAX_INDENT) #define JSON_COMPACT 0x20 #define JSON_ENSURE_ASCII 0x40 #define JSON_SORT_KEYS 0x80 #define JSON_PRESERVE_ORDER 0x100 #define JSON_ENCODE_ANY 0x200 #define JSON_ESCAPE_SLASH 0x400 -#define JSON_REAL_PRECISION(n) (((n)&0x1F) << 11) +#define JSON_REAL_PRECISION(n) (((n) & 0x1F) << 11) #define JSON_EMBED 0x10000 typedef int (*json_dump_callback_t)(const char *buffer, size_t size, void *data); @@ -402,11 +402,17 @@ /* custom memory allocation */ typedef void *(*json_malloc_t)(size_t); +typedef void *(*json_realloc_t)(void *, size_t); typedef void (*json_free_t)(void *); void json_set_alloc_funcs(json_malloc_t malloc_fn, json_free_t free_fn); void json_get_alloc_funcs(json_malloc_t *malloc_fn, json_free_t *free_fn); +void json_set_alloc_funcs2(json_malloc_t malloc_fn, json_realloc_t realloc_fn, + json_free_t free_fn); +void json_get_alloc_funcs2(json_malloc_t *malloc_fn, json_realloc_t *realloc_fn, + json_free_t *free_fn); + /* runtime version checking */ const char *jansson_version_str(void); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 --exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh old/jansson-2.14.1/src/jansson_private.h new/jansson-2.15.0/src/jansson_private.h --- old/jansson-2.14.1/src/jansson_private.h 2022-08-09 20:56:05.000000000 +0200 +++ new/jansson-2.15.0/src/jansson_private.h 2026-01-22 07:37:04.000000000 +0100 @@ -83,9 +83,9 @@ /* Wrappers for custom memory functions */ void *jsonp_malloc(size_t size) JANSSON_ATTRS((warn_unused_result)); +void *jsonp_realloc(void *ptr, size_t originalSize, size_t newSize) + JANSSON_ATTRS((warn_unused_result)); void jsonp_free(void *ptr); -char *jsonp_strndup(const char *str, size_t length) JANSSON_ATTRS((warn_unused_result)); -char *jsonp_strdup(const char *str) JANSSON_ATTRS((warn_unused_result)); char *jsonp_strndup(const char *str, size_t len) JANSSON_ATTRS((warn_unused_result)); /* Circular reference check*/ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 --exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh old/jansson-2.14.1/src/memory.c new/jansson-2.15.0/src/memory.c --- old/jansson-2.14.1/src/memory.c 2022-08-09 20:56:05.000000000 +0200 +++ new/jansson-2.15.0/src/memory.c 2026-01-22 07:37:04.000000000 +0100 @@ -14,10 +14,12 @@ /* C89 allows these to be macros */ #undef malloc +#undef realloc #undef free /* memory function pointers */ static json_malloc_t do_malloc = malloc; +static json_realloc_t do_realloc = realloc; static json_free_t do_free = free; void *jsonp_malloc(size_t size) { @@ -34,7 +36,30 @@ (*do_free)(ptr); } -char *jsonp_strdup(const char *str) { return jsonp_strndup(str, strlen(str)); } +void *jsonp_realloc(void *ptr, size_t originalSize, size_t newSize) { + void *newMemory; + + if (do_realloc) + return (*do_realloc)(ptr, newSize); + + // realloc emulation using malloc and free + if (newSize == 0) { + if (ptr != NULL) + (*do_free)(ptr); + + return NULL; + } else { + newMemory = (*do_malloc)(newSize); + + if ((newMemory != NULL) && (ptr != NULL)) { + memcpy(newMemory, ptr, (originalSize < newSize) ? originalSize : newSize); + + (*do_free)(ptr); + } + + return newMemory; + } +} char *jsonp_strndup(const char *str, size_t len) { char *new_str; @@ -50,6 +75,14 @@ void json_set_alloc_funcs(json_malloc_t malloc_fn, json_free_t free_fn) { do_malloc = malloc_fn; + do_realloc = NULL; + do_free = free_fn; +} + +void json_set_alloc_funcs2(json_malloc_t malloc_fn, json_realloc_t realloc_fn, + json_free_t free_fn) { + do_malloc = malloc_fn; + do_realloc = realloc_fn; do_free = free_fn; } @@ -59,3 +92,12 @@ if (free_fn) *free_fn = do_free; } +void json_get_alloc_funcs2(json_malloc_t *malloc_fn, json_realloc_t *realloc_fn, + json_free_t *free_fn) { + if (malloc_fn) + *malloc_fn = do_malloc; + if (realloc_fn) + *realloc_fn = do_realloc; + if (free_fn) + *free_fn = do_free; +} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 --exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh old/jansson-2.14.1/src/pack_unpack.c new/jansson-2.15.0/src/pack_unpack.c --- old/jansson-2.14.1/src/pack_unpack.c 2022-08-09 20:56:05.000000000 +0200 +++ new/jansson-2.15.0/src/pack_unpack.c 2026-01-22 07:37:04.000000000 +0100 @@ -258,7 +258,7 @@ if (s->has_error) json_decref(value); - if (!s->has_error && json_object_set_new_nocheck(object, key, value)) { + if (!s->has_error && json_object_setn_new_nocheck(object, key, len, value)) { set_error(s, "<internal>", json_error_out_of_memory, "Unable to add key \"%s\"", key); s->has_error = 1; @@ -488,6 +488,7 @@ while (token(s) != '}') { const char *key; + size_t key_len; json_t *value; int opt = 0; @@ -521,6 +522,7 @@ set_error(s, "<args>", json_error_null_value, "NULL object key"); goto out; } + key_len = strlen(key); next_token(s); @@ -533,7 +535,7 @@ /* skipping */ value = NULL; } else { - value = json_object_get(root, key); + value = json_object_getn(root, key, key_len); if (!value && !opt) { set_error(s, "<validation>", json_error_item_not_found, "Object item not found: %s", key); @@ -544,7 +546,7 @@ if (unpack(s, value, ap)) goto out; - hashtable_set(&key_set, key, strlen(key), json_null()); + hashtable_set(&key_set, key, key_len, json_null()); next_token(s); } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 --exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh old/jansson-2.14.1/src/strbuffer.c new/jansson-2.15.0/src/strbuffer.c --- old/jansson-2.14.1/src/strbuffer.c 2024-03-15 21:54:02.000000000 +0100 +++ new/jansson-2.15.0/src/strbuffer.c 2026-01-22 07:37:04.000000000 +0100 @@ -16,7 +16,7 @@ #define STRBUFFER_MIN_SIZE 16 #define STRBUFFER_FACTOR 2 -#define STRBUFFER_SIZE_MAX ((size_t)-1) +#define STRBUFFER_SIZE_MAX ((size_t)(-1)) int strbuffer_init(strbuffer_t *strbuff) { strbuff->size = STRBUFFER_MIN_SIZE; @@ -70,13 +70,10 @@ new_size = max(strbuff->size * STRBUFFER_FACTOR, strbuff->length + size + 1); - new_value = jsonp_malloc(new_size); + new_value = jsonp_realloc(strbuff->value, strbuff->size, new_size); if (!new_value) return -1; - memcpy(new_value, strbuff->value, strbuff->length); - - jsonp_free(strbuff->value); strbuff->value = new_value; strbuff->size = new_size; } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 --exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh old/jansson-2.14.1/src/value.c new/jansson-2.15.0/src/value.c --- old/jansson-2.14.1/src/value.c 2022-08-09 20:56:05.000000000 +0200 +++ new/jansson-2.15.0/src/value.c 2026-01-22 07:37:04.000000000 +0100 @@ -507,7 +507,7 @@ memcpy(&dest[dpos], &src[spos], count * sizeof(json_t *)); } -static json_t **json_array_grow(json_array_t *array, size_t amount, int copy) { +static json_t **json_array_grow(json_array_t *array, size_t amount) { size_t new_size; json_t **old_table, **new_table; @@ -517,20 +517,15 @@ old_table = array->table; new_size = max(array->size + amount, array->size * 2); - new_table = jsonp_malloc(new_size * sizeof(json_t *)); + new_table = jsonp_realloc(old_table, array->size * sizeof(json_t *), + new_size * sizeof(json_t *)); if (!new_table) return NULL; array->size = new_size; array->table = new_table; - if (copy) { - array_copy(array->table, 0, old_table, 0, array->entries); - jsonp_free(old_table); - return array->table; - } - - return old_table; + return array->table; } int json_array_append_new(json_t *json, json_t *value) { @@ -545,7 +540,7 @@ } array = json_to_array(json); - if (!json_array_grow(array, 1, 1)) { + if (!json_array_grow(array, 1)) { json_decref(value); return -1; } @@ -558,7 +553,6 @@ int json_array_insert_new(json_t *json, size_t index, json_t *value) { json_array_t *array; - json_t **old_table; if (!value) return -1; @@ -574,17 +568,11 @@ return -1; } - old_table = json_array_grow(array, 1, 0); - if (!old_table) { + if (!json_array_grow(array, 1)) { json_decref(value); return -1; } - - if (old_table != array->table) { - array_copy(array->table, 0, old_table, 0, index); - array_copy(array->table, index + 1, old_table, index, array->entries - index); - jsonp_free(old_table); - } else + if (index != array->entries) array_move(array, index + 1, index, array->entries - index); array->table[index] = value; @@ -638,7 +626,7 @@ array = json_to_array(json); other = json_to_array(other_json); - if (!json_array_grow(array, other->entries, 1)) + if (!json_array_grow(array, other->entries)) return -1; for (i = 0; i < other->entries; i++) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 --exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh old/jansson-2.14.1/test/suites/api/Makefile.am new/jansson-2.15.0/test/suites/api/Makefile.am --- old/jansson-2.14.1/test/suites/api/Makefile.am 2022-08-09 20:56:05.000000000 +0200 +++ new/jansson-2.15.0/test/suites/api/Makefile.am 2026-01-22 07:37:04.000000000 +0100 @@ -3,6 +3,7 @@ check_PROGRAMS = \ test_array \ test_chaos \ + test_chaos_realloc \ test_copy \ test_dump \ test_dump_callback \ @@ -12,6 +13,7 @@ test_load_callback \ test_loadb \ test_memory_funcs \ + test_memory_funcs_realloc \ test_number \ test_object \ test_pack \ @@ -22,6 +24,7 @@ test_array_SOURCES = test_array.c util.h test_chaos_SOURCES = test_chaos.c util.h +test_chaos_realloc_SOURCES = test_chaos_realloc.c util.h test_copy_SOURCES = test_copy.c util.h test_dump_SOURCES = test_dump.c util.h test_dump_callback_SOURCES = test_dump_callback.c util.h @@ -29,6 +32,7 @@ test_load_SOURCES = test_load.c util.h test_loadb_SOURCES = test_loadb.c util.h test_memory_funcs_SOURCES = test_memory_funcs.c util.h +test_memory_funcs_realloc_SOURCES = test_memory_funcs_realloc.c util.h test_number_SOURCES = test_number.c util.h test_object_SOURCES = test_object.c util.h test_pack_SOURCES = test_pack.c util.h diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 --exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh old/jansson-2.14.1/test/suites/api/test_chaos_realloc.c new/jansson-2.15.0/test/suites/api/test_chaos_realloc.c --- old/jansson-2.14.1/test/suites/api/test_chaos_realloc.c 1970-01-01 01:00:00.000000000 +0100 +++ new/jansson-2.15.0/test/suites/api/test_chaos_realloc.c 2026-01-22 07:37:04.000000000 +0100 @@ -0,0 +1,180 @@ +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif + +#include "util.h" +#include <jansson.h> +#include <stdio.h> +#include <string.h> + +static int chaos_pos = 0; +static int chaos_fail = 0; +#define CHAOS_MAX_FAILURE 200 + +void *chaos_malloc(size_t size) { + if (chaos_pos == chaos_fail) + return NULL; + + chaos_pos++; + + return malloc(size); +} + +void *chaos_realloc(void *ptr, size_t size) { + if (chaos_pos == chaos_fail) { + return NULL; + } + + chaos_pos++; + + return realloc(ptr, size); +} + +void chaos_free(void *obj) { free(obj); } + +/* Test all potential allocation failures. */ +#define chaos_loop(condition, code, cleanup) \ + { \ + chaos_pos = chaos_fail = 0; \ + while (condition) { \ + if (chaos_fail > CHAOS_MAX_FAILURE) \ + fail("too many chaos failures"); \ + code chaos_pos = 0; \ + chaos_fail++; \ + } \ + cleanup \ + } + +#define chaos_loop_new_value(json, initcall) \ + chaos_loop(!json, json = initcall;, json_decref(json); json = NULL;) + +int test_unpack() { + int ret = -1; + int v1; + int v2; + json_error_t error; + json_t *root = json_pack("{s:i, s:i, s:i, s:i}", "n1", 1, "n2", 2, "n3", 3, "n4", 4); + + if (!root) + return -1; + + if (!json_unpack_ex(root, &error, JSON_STRICT, "{s:i, s:i}", "n1", &v1, "n2", &v2)) + fail("Unexpected success"); + + if (json_error_code(&error) != json_error_end_of_input_expected) { + if (json_error_code(&error) != json_error_out_of_memory) + fail("Unexpected error code"); + + goto out; + } + + if (strcmp(error.text, "2 object item(s) left unpacked: n3, n4")) + goto out; + + ret = 0; + +out: + json_decref(root); + return ret; +} + +int dump_chaos_callback(const char *buffer, size_t size, void *data) { + json_t *obj = json_object(); + + (void)buffer; + (void)size; + (void)data; + + if (!obj) + return -1; + + json_decref(obj); + + return 0; +} + +static void test_chaos_realloc() { + json_malloc_t orig_malloc; + json_realloc_t orig_realloc; + json_free_t orig_free; + json_t *json = NULL; + json_t *obj = json_object(); + json_t *arr1 = json_array(); + json_t *arr2 = json_array(); + json_t *txt = json_string("test"); + json_t *intnum = json_integer(1); + json_t *dblnum = json_real(0.5); + char *dumptxt = NULL; + json_t *dumpobj = json_pack("{s:[iiis], s:s}", "key1", 1, 2, 3, "txt", "key2", "v2"); + int keyno; + + if (!obj || !arr1 || !arr2 || !txt || !intnum || !dblnum || !dumpobj) + fail("failed to allocate basic objects"); + + json_get_alloc_funcs2(&orig_malloc, &orig_realloc, &orig_free); + json_set_alloc_funcs2(chaos_malloc, chaos_realloc, chaos_free); + + chaos_loop_new_value(json, json_pack("{s:s}", "key", "value")); + chaos_loop_new_value(json, json_pack("{s:[]}", "key")); + chaos_loop_new_value(json, json_pack("[biIf]", 1, 1, (json_int_t)1, 1.0)); + chaos_loop_new_value(json, json_pack("[s*,s*]", "v1", "v2")); + chaos_loop_new_value(json, json_pack("o", json_incref(txt))); + chaos_loop_new_value(json, json_pack("O", txt)); + chaos_loop_new_value(json, json_pack("s++", "a", "long string to force realloc", + "another long string to force yet another " + "reallocation of the string because " + "that's what we are testing.")); + + chaos_loop(test_unpack(), , ); + + chaos_loop(json_dump_callback(dumpobj, dump_chaos_callback, NULL, JSON_INDENT(1)), + , ); + chaos_loop(json_dump_callback(dumpobj, dump_chaos_callback, NULL, + JSON_INDENT(1) | JSON_SORT_KEYS), + , ); + chaos_loop(!dumptxt, dumptxt = json_dumps(dumpobj, JSON_COMPACT);, free(dumptxt); + dumptxt = NULL;); + + chaos_loop_new_value(json, json_copy(obj)); + chaos_loop_new_value(json, json_deep_copy(obj)); + + chaos_loop_new_value(json, json_copy(arr1)); + chaos_loop_new_value(json, json_deep_copy(arr1)); + + chaos_loop_new_value(json, json_copy(txt)); + chaos_loop_new_value(json, json_copy(intnum)); + chaos_loop_new_value(json, json_copy(dblnum)); + +#define JSON_LOAD_TXT "{\"n\":[1,2,3,4,5,6,7,8,9,10]}" + chaos_loop_new_value(json, json_loads(JSON_LOAD_TXT, 0, NULL)); + chaos_loop_new_value(json, json_loadb(JSON_LOAD_TXT, strlen(JSON_LOAD_TXT), 0, NULL)); + + chaos_loop_new_value(json, json_sprintf("%s", "string")); + + for (keyno = 0; keyno < 100; ++keyno) { +#if !defined(_MSC_VER) || _MSC_VER >= 1900 + /* Skip this test on old Windows compilers. */ + char testkey[10]; + + snprintf(testkey, sizeof(testkey), "test%d", keyno); + chaos_loop(json_object_set_new_nocheck(obj, testkey, json_object()), , ); +#endif + chaos_loop(json_array_append_new(arr1, json_null()), , ); + chaos_loop(json_array_insert_new(arr2, 0, json_null()), , ); + } + + chaos_loop(json_array_extend(arr1, arr2), , ); + chaos_loop(json_string_set_nocheck(txt, "test"), , ); + + json_set_alloc_funcs2(orig_malloc, orig_realloc, orig_free); + + json_decref(obj); + json_decref(arr1); + json_decref(arr2); + json_decref(txt); + json_decref(intnum); + json_decref(dblnum); + json_decref(dumpobj); +} + +static void run_tests() { test_chaos_realloc(); } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 --exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh old/jansson-2.14.1/test/suites/api/test_memory_funcs.c new/jansson-2.15.0/test/suites/api/test_memory_funcs.c --- old/jansson-2.14.1/test/suites/api/test_memory_funcs.c 2022-08-09 20:56:05.000000000 +0200 +++ new/jansson-2.15.0/test/suites/api/test_memory_funcs.c 2026-01-22 07:37:04.000000000 +0100 @@ -83,6 +83,8 @@ static void *secure_malloc(size_t size) { /* Store the memory area size in the beginning of the block */ void *ptr = malloc(size + 8); + if (!ptr) + return NULL; *((size_t *)ptr) = size; return (char *)ptr + 8; } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 --exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh old/jansson-2.14.1/test/suites/api/test_memory_funcs_realloc.c new/jansson-2.15.0/test/suites/api/test_memory_funcs_realloc.c --- old/jansson-2.14.1/test/suites/api/test_memory_funcs_realloc.c 1970-01-01 01:00:00.000000000 +0100 +++ new/jansson-2.15.0/test/suites/api/test_memory_funcs_realloc.c 2026-01-22 07:37:04.000000000 +0100 @@ -0,0 +1,142 @@ +#include <jansson.h> +#include <string.h> + +#include "util.h" + +static int malloc_called = 0; +static int realloc_called = 0; +static int free_called = 0; +static size_t malloc_used = 0; + +/* helpers */ +static void create_and_free_complex_object() { + json_t *obj; + + obj = json_pack("{s:i,s:n,s:b,s:b,s:{s:s},s:[i,i,i]}", "foo", 42, "bar", "baz", 1, + "qux", 0, "alice", "bar", "baz", "bob", 9, 8, 7); + + json_decref(obj); +} + +static void create_and_free_object_with_oom() { + int i; + char key[4]; + json_t *obj = json_object(); + + for (i = 0; i < 10; i++) { + snprintf(key, sizeof key, "%d", i); + json_object_set_new(obj, key, json_integer(i)); + } + + json_decref(obj); +} + +static void *my_malloc(size_t size) { + malloc_called = 1; + return malloc(size); +} + +static void my_free(void *ptr) { + free_called = 1; + free(ptr); +} + +static void *my_realloc(void *ptr, size_t size) { + realloc_called = 1; + return realloc(ptr, size); +} + +static void test_simple2() { + json_malloc_t mfunc = NULL; + json_realloc_t rfunc = NULL; + json_free_t ffunc = NULL; + + json_set_alloc_funcs2(my_malloc, my_realloc, my_free); + json_get_alloc_funcs2(&mfunc, &rfunc, &ffunc); + create_and_free_complex_object(); + + if (malloc_called != 1 || free_called != 1 || mfunc != my_malloc || + rfunc != my_realloc || ffunc != my_free) + fail("Custom allocation failed"); +} + +static void *oom_malloc(size_t size) { + if (malloc_used + size > 800) + return NULL; + + malloc_used += size; + return malloc(size); +} + +static void oom_free(void *ptr) { + free_called++; + free(ptr); +} + +static void *oom_realloc(void *ptr, size_t size) { + if (malloc_used + size > 800) { + return NULL; + } + + malloc_used += size; + return realloc(ptr, size); +} + +static void test_oom2() { + free_called = 0; + malloc_used = 0; + json_set_alloc_funcs2(oom_malloc, oom_realloc, oom_free); + create_and_free_object_with_oom(); + + if (free_called == 0) + fail("Allocation with OOM failed"); +} + +/* + Test the secure memory functions code given in the API reference + documentation, but by using plain memset instead of + guaranteed_memset(). +*/ + +static void *secure_malloc(size_t size) { + /* Store the memory area size in the beginning of the block */ + void *ptr = malloc(size + 8); + if (!ptr) + return NULL; + *((size_t *)ptr) = size; + return (char *)ptr + 8; +} + +static void *secure_realloc(void *ptr, size_t size) { + /* Store the memory area size in the beginning of the block */ + ptr = realloc(ptr, size + 8); + *((size_t *)ptr) = size; + return (char *)ptr + 8; +} + +static void secure_free(void *ptr) { + size_t size; + + ptr = (char *)ptr - 8; + size = *((size_t *)ptr); + + /*guaranteed_*/ memset(ptr, 0, size + 8); + free(ptr); +} + +static void test_secure_funcs2(void) { + json_set_alloc_funcs2(secure_malloc, secure_realloc, secure_free); + create_and_free_complex_object(); +} + +static void test_bad_args2(void) { + /* The result of this test is not crashing. */ + json_get_alloc_funcs2(NULL, NULL, NULL); +} + +static void run_tests() { + test_simple2(); + test_secure_funcs2(); + test_oom2(); + test_bad_args2(); +} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 --exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh old/jansson-2.14.1/test-driver new/jansson-2.15.0/test-driver --- old/jansson-2.14.1/test-driver 2025-03-23 13:18:45.000000000 +0100 +++ new/jansson-2.15.0/test-driver 2026-01-24 21:54:57.000000000 +0100 @@ -1,9 +1,9 @@ #! /bin/sh # test-driver - basic testsuite driver script. -scriptversion=2024-06-19.01; # UTC +scriptversion=2025-06-18.21; # UTC -# Copyright (C) 2011-2024 Free Software Foundation, Inc. +# Copyright (C) 2011-2025 Free Software Foundation, Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -152,9 +152,9 @@ # Local Variables: # mode: shell-script # sh-indentation: 2 -# eval: (add-hook 'before-save-hook 'time-stamp) +# eval: (add-hook 'before-save-hook 'time-stamp nil t) # time-stamp-start: "scriptversion=" -# time-stamp-format: "%:y-%02m-%02d.%02H" +# time-stamp-format: "%Y-%02m-%02d.%02H" # time-stamp-time-zone: "UTC0" # time-stamp-end: "; # UTC" # End:
