]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Avoid getcwd(0, PATH_MAX) for GNU libc 1529/head
authorOwen W. Taylor <otaylor@fishsoup.net>
Wed, 12 May 2021 20:37:16 +0000 (16:37 -0400)
committerOwen W. Taylor <otaylor@fishsoup.net>
Wed, 12 May 2021 20:44:11 +0000 (16:44 -0400)
Recent versions of GNU libc and GCC produce a warning on getcwd(0, PATH_MAX):

 test_main.c: In function ‘get_refdir’:
 test_main.c:3684:8: error: argument 1 is null but the corresponding size argument 2 value is 4096 [-Werror=nonnull]
   3684 |  pwd = getcwd(NULL, PATH_MAX);/* Solaris getcwd needs the size. */

This is because getcwd() is marked with the 'write_only (1, 2)' attribute.

Using the alternate getcwd(NULL, 0) path which is supported by GNU libc avoids this.

libarchive/test/test_read_disk_directory_traversals.c
libarchive/test/test_sparse_basic.c
test_utils/test_main.c

index 9efa74281b124adfc91b4d96b64625f8d47bb471..d24d1436974a02fe0a6a0b6a35cda2c5fb94b4eb 100644 (file)
@@ -528,7 +528,7 @@ test_basic(void)
         */
 
        /* Save current working directory. */
-#ifdef PATH_MAX
+#if defined(PATH_MAX) && !defined(__GLIBC__)
        initial_cwd = getcwd(NULL, PATH_MAX);/* Solaris getcwd needs the size. */
 #else
        initial_cwd = getcwd(NULL, 0);
@@ -560,7 +560,7 @@ test_basic(void)
        failure(
            "Current working directory does not return to the initial"
            "directory");
-#ifdef PATH_MAX
+#if defined(PATH_MAX) && !defined(__GLIBC__)
        cwd = getcwd(NULL, PATH_MAX);/* Solaris getcwd needs the size. */
 #else
        cwd = getcwd(NULL, 0);
index 0fbb7f7bf467862e1c5bcdf794b8481a1c2620d7..43e87df5245183a4119aa600a87604f9283ccdc0 100644 (file)
@@ -577,7 +577,7 @@ DEFINE_TEST(test_sparse_basic)
 
        /* Check if the filesystem where CWD on can
         * report the number of the holes of a sparse file. */
-#ifdef PATH_MAX
+#if defined(PATH_MAX) && !defined(__GLIBC__)
        cwd = getcwd(NULL, PATH_MAX);/* Solaris getcwd needs the size. */
 #else
        cwd = getcwd(NULL, 0);
@@ -637,7 +637,7 @@ DEFINE_TEST(test_fully_sparse_files)
 
        /* Check if the filesystem where CWD on can
         * report the number of the holes of a sparse file. */
-#ifdef PATH_MAX
+#if defined(PATH_MAX) && !defined(__GLIBC__)
        cwd = getcwd(NULL, PATH_MAX);/* Solaris getcwd needs the size. */
 #else
        cwd = getcwd(NULL, 0);
index ef066eb67d99f59f581ad8f483daffed6ef4e94b..c1c03cdafd7004b7dac79c95ef28d5f3598d5838 100644 (file)
@@ -3680,7 +3680,7 @@ get_refdir(const char *d)
        }
 
        /* Get the current dir. */
-#ifdef PATH_MAX
+#if defined(PATH_MAX) && !defined(__GLIBC__)
        pwd = getcwd(NULL, PATH_MAX);/* Solaris getcwd needs the size. */
 #else
        pwd = getcwd(NULL, 0);
@@ -3775,7 +3775,7 @@ main(int argc, char **argv)
        (void)argc; /* UNUSED */
 
        /* Get the current dir. */
-#ifdef PATH_MAX
+#if defined(PATH_MAX) && !defined(__GLIBC__)
        pwd = getcwd(NULL, PATH_MAX);/* Solaris getcwd needs the size. */
 #else
        pwd = getcwd(NULL, 0);