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.
This commit is contained in:
Sangamesh Mallayya committed 2026-09-21 01:03:16 -05:00
1 parent a559871165
commit 52f57ec18a
1 file changed
+6 -1
+6 -1
View File
@@ -16,6 +16,11 @@
#define PATH_MAX 256 #define PATH_MAX 256
#endif #endif
/* printf("%s", NULL) prints emptry string on AIX.
* Use this macro to guard all printf %s args that may be NULL*/
#define STR_OR_NULL(s) ((s) ? (s) : "(null)")
void test_json_patch_op(struct json_object *jo) void test_json_patch_op(struct json_object *jo)
{ {
const char *comment = json_object_get_string(json_object_object_get(jo, "comment")); const char *comment = json_object_get_string(json_object_object_get(jo, "comment"));
@@ -29,7 +34,7 @@ void test_json_patch_op(struct json_object *jo)
int ret; int ret;
printf("Testing '%s', doc '%s' patch '%s' : ", printf("Testing '%s', doc '%s' patch '%s' : ",
comment ? comment : error_s, STR_OR_NULL(comment ? comment : error_s),
json_object_get_string(doc), json_object_get_string(doc),
json_object_get_string(patch)); json_object_get_string(patch));
if (!error && !have_expected) { if (!error && !have_expected) {