From 8946c27306abed7065afad3f015df5ee81e72ad2 Mon Sep 17 00:00:00 2001 From: Kimplul Date: Fri, 1 May 2026 20:35:00 +0300 Subject: add support for coverage --- src/path.c | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) (limited to 'src/path.c') diff --git a/src/path.c b/src/path.c index 87cd26b..5502a7b 100644 --- a/src/path.c +++ b/src/path.c @@ -15,6 +15,8 @@ #include #include +#include +#include char *fwd_basename(const char *file) { @@ -25,10 +27,19 @@ char *fwd_basename(const char *file) break; } + char *s = NULL; if (n == 0) - return strdup(file); + s = strdupc(file); + else + s = strndupc(file + n + 1, l - n); + + if (!s) { + internal_error("failed allocating basename"); + return NULL; + } - return strndup(file + n + 1, l - n); + track_ptr(s); + return s; } char *fwd_dirname(const char *file) @@ -40,7 +51,14 @@ char *fwd_dirname(const char *file) break; } - return strndup(file, n); + char *s = strndupc(file, n); + if (!s) { + internal_error("failed allocating dirname"); + return NULL; + } + + track_ptr(s); + return s; } char *fwd_cwdname() @@ -52,13 +70,15 @@ char *fwd_cwdname() else size = (size_t)path_max; - char *buf = malloc(size); - if (!buf) + char *buf = mallocc(size); + if (!buf) { + internal_error("failed allocating cwd buf"); return NULL; + } + track_ptr(buf); if (!getcwd(buf, size)) { error("%s\n", strerror(errno)); - free(buf); return NULL; } -- cgit v1.2.3