[PATCH 1/4] unit: Fix incorrect basename usage
Bastien Nocera <[email protected]> Tue, 17 Mar 2026 15:28:54 +0100
| Newsgroups | dev.linux.lists.ell |
|---|---|
| Message-ID | <[email protected]> |
The code called basename(), which requires either relying on the GNU
libc, or including libgen.h to get access to the POSIX implementation.
As neither was done, and the output of basename() was not freed, it's
likely that the intent was to use the library-exported l_basename()
instead which does not output an allocated string.
ninja: job failed: clang -Isubprojects/ell-0.83/unit/test-path.p -Isubprojects/ell-0.83/unit -I../subprojects/ell-0.83/unit -Isubprojects/ell-0.83 -I../subprojects/ell-0.83 -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -O0 -g -DHAVE_CONFIG_H '-DUNITDIR="/home/runner/work/wrapdb/wrapdb/subprojects/ell-0.83/unit/"' '-DCERTDIR="/home/runner/work/wrapdb/wrapdb/_build/subprojects/ell-0.83/unit/"' -MD -MQ subprojects/ell-0.83/unit/test-path.p/test-path.c.o -MF subprojects/ell-0.83/unit/test-path.p/test-path.c.o.d -o subprojects/ell-0.83/unit/test-path.p/test-path.c.o -c ../subprojects/ell-0.83/unit/test-path.c
../subprojects/ell-0.83/unit/test-path.c:65:9: error: call to undeclared function 'basename'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
65 | base = basename(tmp_path);
| ^
../subprojects/ell-0.83/unit/test-path.c:65:9: note: did you mean 'l_basename'?
../subprojects/ell-0.83/ell/path.h:20:13: note: 'l_basename' declared here
20 | const char *l_basename(const char *path);
| ^
../subprojects/ell-0.83/unit/test-path.c:65:7: error: incompatible integer to pointer conversion assigning to 'char *' from 'int' [-Wint-conversion]
65 | base = basename(tmp_path);
| ^ ~~~~~~~~~~~~~~~~~~
---
unit/test-path.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/unit/test-path.c b/unit/test-path.c
index 1f744234c395..f01fa526aaa1 100644
--- a/unit/test-path.c
+++ b/unit/test-path.c
@@ -55,14 +55,14 @@ static void test_path_find(const void *data)
static const char *cant_find = "/foo:/bar:/dir:fr";
static const char *can_find = "/tmp";
char *tmp_path = l_strdup("/tmp/foobarXXXXXX.tmp");
- char *base;
+ const char *base;
char *path;
int fd;
fd = L_TFR(mkostemps(tmp_path, 4, O_CLOEXEC));
assert(fd > 0);
L_TFR(close(fd));
- base = basename(tmp_path);
+ base = l_basename(tmp_path);
assert(l_path_find(base, cant_find, F_OK) == NULL);
--
2.53.0