From 97702475f8e59a160015d45417cbe805fbcdf590 Mon Sep 17 00:00:00 2001 From: Pu Cheng Date: Fri, 20 Nov 2026 05:49:41 +0800 Subject: [PATCH] in BUGFIX ly_in_filepath() error value for a handler of another type When the handler was NULL or not of the LY_IN_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/in.c | 2 +- tests/utests/basic/test_inout.c | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/in.c b/src/in.c index c92739147..67bd06e33 100644 --- a/src/in.c +++ b/src/in.c @@ -288,7 +288,7 @@ ly_in_filepath(struct ly_in *in, const char *filepath, size_t len) int fd, prev_fd; char *fp = NULL; - LY_CHECK_ARG_RET(NULL, in, in->type == LY_IN_FILEPATH, filepath ? NULL : ((void *)-1)); + LY_CHECK_ARG_RET(NULL, in, in->type == LY_IN_FILEPATH, ((void *)-1)); if (!filepath) { return in->method.fpath.filepath; diff --git a/tests/utests/basic/test_inout.c b/tests/utests/basic/test_inout.c index c5e1d5c9c..249050a04 100644 --- a/tests/utests/basic/test_inout.c +++ b/tests/utests/basic/test_inout.c @@ -195,6 +195,13 @@ test_input_filepath(void **UNUSED(state)) assert_int_equal(LY_EINVAL, ly_in_new_filepath(NULL, 0, NULL)); assert_int_equal(LY_EINVAL, ly_in_new_filepath(path1, 0, NULL)); assert_ptr_equal(((void *)-1), ly_in_filepath(NULL, NULL, 0)); + assert_ptr_equal(((void *)-1), ly_in_filepath(NULL, path1, 0)); + + /* changing the file path of a handler of another type is an error */ + assert_int_equal(LY_SUCCESS, ly_in_new_memory("data", &in)); + assert_ptr_equal(((void *)-1), ly_in_filepath(in, path1, 0)); + assert_int_equal(LY_IN_MEMORY, ly_in_type(in)); + ly_in_free(in, 0); assert_int_equal(LY_SUCCESS, ly_in_new_filepath(path1, 0, &in)); assert_int_equal(LY_IN_FILEPATH, ly_in_type(in));