bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] test-stat: don't allocate PATH_MAX bytes


From: Eric Blake
Subject: [PATCH] test-stat: don't allocate PATH_MAX bytes
Date: Mon, 20 Jun 2011 15:41:47 -0600

POSIX allows systems (like Hurd) that don't define PATH_MAX, or
which define it larger than a reasonable stack allocation should
be.  The test originally used stack allocation to avoid portability
problems with getcwd, but the getcwd-lgpl module solves those.

* tests/test-stat.h (test_stat_func): Don't stack-allocate a
PATH_MAX-sized buffer.
* modules/openat-tests (Depends-on): Add getcwd-lgpl, drop pathmax.
* modules/stat-tests (Depends-on): Likewise.
* tests/test-fstatat.c (includes): Drop pathmax.h.
* tests/test-stat.c (includes): Likewise.
Reported by Bruno Haible.

Signed-off-by: Eric Blake <address@hidden>
---

Fixing this test proved easy enough.

 ChangeLog            |   11 +++++++++++
 modules/openat-tests |    2 +-
 modules/stat-tests   |    2 +-
 tests/test-fstatat.c |    1 -
 tests/test-stat.c    |    1 -
 tests/test-stat.h    |    4 ++--
 6 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 7fe9017..1758d67 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2011-06-20  Eric Blake  <address@hidden>
+
+       test-stat: don't allocate PATH_MAX bytes
+       * tests/test-stat.h (test_stat_func): Don't stack-allocate a
+       PATH_MAX-sized buffer.
+       * modules/openat-tests (Depends-on): Add getcwd-lgpl, drop pathmax.
+       * modules/stat-tests (Depends-on): Likewise.
+       * tests/test-fstatat.c (includes): Drop pathmax.h.
+       * tests/test-stat.c (includes): Likewise.
+       Reported by Bruno Haible.
+
 2011-06-20  Bruno Haible  <address@hidden>

        float: Work around <float.h> bugs on FreeBSD/x86, AIX with GCC, IRIX.
diff --git a/modules/openat-tests b/modules/openat-tests
index 8b0a2b9..b83fb72 100644
--- a/modules/openat-tests
+++ b/modules/openat-tests
@@ -16,9 +16,9 @@ tests/signature.h
 tests/macros.h

 Depends-on:
+getcwd-lgpl
 ignore-value
 mgetgroups
-pathmax
 progname
 usleep
 stat-time
diff --git a/modules/stat-tests b/modules/stat-tests
index 74d558c..9c00ce5 100644
--- a/modules/stat-tests
+++ b/modules/stat-tests
@@ -5,7 +5,7 @@ tests/signature.h
 tests/macros.h

 Depends-on:
-pathmax
+getcwd-lgpl
 same-inode
 stdbool
 symlink
diff --git a/tests/test-fstatat.c b/tests/test-fstatat.c
index dda0cd2..aef1136 100644
--- a/tests/test-fstatat.c
+++ b/tests/test-fstatat.c
@@ -31,7 +31,6 @@ SIGNATURE_CHECK (fstatat, int, (int, char const *, struct 
stat *, int));
 #include <unistd.h>

 #include "openat.h"
-#include "pathmax.h"
 #include "progname.h"
 #include "same-inode.h"
 #include "ignore-value.h"
diff --git a/tests/test-stat.c b/tests/test-stat.c
index 4cda089..cd74491 100644
--- a/tests/test-stat.c
+++ b/tests/test-stat.c
@@ -33,7 +33,6 @@ SIGNATURE_CHECK (stat, int, (char const *, struct stat *));
 #include <stdio.h>
 #include <unistd.h>

-#include "pathmax.h"
 #include "same-inode.h"
 #include "macros.h"

diff --git a/tests/test-stat.h b/tests/test-stat.h
index 22552dc..3c8f7ad 100644
--- a/tests/test-stat.h
+++ b/tests/test-stat.h
@@ -27,9 +27,9 @@ test_stat_func (int (*func) (char const *, struct stat *), 
bool print)
 {
   struct stat st1;
   struct stat st2;
-  char cwd[PATH_MAX];
+  char *cwd = getcwd (NULL, 0);

-  ASSERT (getcwd (cwd, PATH_MAX) == cwd);
+  ASSERT (cwd);
   ASSERT (func (".", &st1) == 0);
   ASSERT (func ("./", &st2) == 0);
   ASSERT (SAME_INODE (st1, st2));
-- 
1.7.4.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]