From b306a7811f8b9604304d49ad3bf4d4a6e64ea7f9 Mon Sep 17 00:00:00 2001 From: Pu Cheng Date: Fri, 20 Nov 2026 05:49:41 +0800 Subject: [PATCH] out BUGFIX ly_out_filepath() error value for a handler of another type When the handler was NULL or not of the LY_OUT_FILEPATH type, the argument check returned NULL, the documented success value, for a change of the file path. Return ((void *)-1) for both a change and a query. --- src/out.c | 2 +- tests/utests/basic/test_inout.c | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/out.c b/src/out.c index 110bb724e..65d7820ae 100644 --- a/src/out.c +++ b/src/out.c @@ -366,7 +366,7 @@ ly_out_filepath(struct ly_out *out, const char *filepath) { FILE *f; - LY_CHECK_ARG_RET(NULL, out, out->type == LY_OUT_FILEPATH, filepath ? NULL : ((void *)-1)); + LY_CHECK_ARG_RET(NULL, out, out->type == LY_OUT_FILEPATH, ((void *)-1)); if (!filepath) { return out->method.fpath.filepath; diff --git a/tests/utests/basic/test_inout.c b/tests/utests/basic/test_inout.c index c5e1d5c9c..36d9ba6b4 100644 --- a/tests/utests/basic/test_inout.c +++ b/tests/utests/basic/test_inout.c @@ -341,6 +341,14 @@ test_output_filepath(void **UNUSED(state)) char buf[31] = {0}; const char *fp1 = TEST_OUTPUT_FILE; const char *fp2 = TEST_OUTPUT_FILE2; + char *mem = NULL; + + /* changing the file path of a NULL handler or a handler of another type is an error */ + assert_ptr_equal(((void *)-1), ly_out_filepath(NULL, fp1)); + assert_int_equal(LY_SUCCESS, ly_out_new_memory(&mem, 0, &out)); + assert_ptr_equal(((void *)-1), ly_out_filepath(out, fp1)); + assert_int_equal(LY_OUT_MEMORY, ly_out_type(out)); + ly_out_free(out, NULL, 1); /* manipulate with the handler */ assert_int_equal(LY_SUCCESS, ly_out_new_filepath(fp1, &out));