From 1420be7916429425f826a214d2bc7e1e19ae11e8 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Wed, 23 Aug 2023 17:58:15 -0400 Subject: Improve test coverage --- src/posix/filesystem_posix.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'src/posix') diff --git a/src/posix/filesystem_posix.c b/src/posix/filesystem_posix.c index 8d65611..a5ac857 100644 --- a/src/posix/filesystem_posix.c +++ b/src/posix/filesystem_posix.c @@ -429,22 +429,23 @@ zix_current_path(ZixAllocator* const allocator) { #if defined(PATH_MAX) // Some POSIX systems have a static PATH_MAX so we can store it on the stack - char buffer[PATH_MAX] = {0}; - if (getcwd(buffer, PATH_MAX)) { - return copy_path(allocator, buffer, strlen(buffer)); - } + char buffer[PATH_MAX] = {0}; + char* const cwd = getcwd(buffer, PATH_MAX); + return cwd ? copy_path(allocator, cwd, strlen(cwd)) : NULL; #elif USE_PATHCONF // Others don't so we have to query PATH_MAX at runtime to allocate the result const size_t size = max_path_size(); char* const buffer = (char*)zix_calloc(allocator, size, 1); char* const current = getcwd(buffer, size); - if (current) { - return current; + if (!current) { + zix_free(allocator, buffer); } - zix_free(allocator, buffer); -#endif + return current; +#else return NULL; + +#endif } -- cgit v1.2.1