util: return early when listing files from a NULL directory list

For consistency with "no matching file found" return a single-null-entry
array.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1212>
This commit is contained in:
Peter Hutterer 2025-05-28 11:33:57 +10:00 committed by Marge Bot
parent d5761547da
commit 46950de903
2 changed files with 11 additions and 0 deletions

View file

@ -87,6 +87,12 @@ list_files(const char **directories,
{
struct list files = LIST_INIT(files);
if (!directories) {
if (nfiles_out)
*nfiles_out = 0;
return zalloc(1 * sizeof(char*));
}
const char **d = directories;
while (*d) {
struct list new_files = LIST_INIT(new_files);

View file

@ -220,6 +220,11 @@ START_TEST(find_files_test)
litest_assert_int_eq(nfiles, (size_t)0);
litest_assert_ptr_notnull(empty_path);
litest_assert_ptr_null(empty_path[0]);
_autostrvfree_ char** also_empty_path = list_files(NULL, "suf", &nfiles);
litest_assert_int_eq(nfiles, (size_t)0);
litest_assert_ptr_notnull(also_empty_path);
litest_assert_ptr_null(also_empty_path[0]);
}
END_TEST