From a5009b0c65c11829cedeeb2b63ec6a4261d6bddb Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Fri, 18 Apr 2025 15:05:10 +0200 Subject: [PATCH] getlogin_r tests: Remove xalloc dependency. * tests/test-getlogin.c (main): Don't assume the putenv argument is unmodified. * tests/test-getlogin_r.c: Do not include xalloc.h. (main): Use a static rather than heap storage. * modules/getlogin_r-tests (Depends-on): Remove xalloc. (test_getlogin_LDADD): Remove @LIBINTL@. --- ChangeLog | 10 ++++++++++ modules/getlogin_r-tests | 3 +-- tests/test-getlogin.c | 12 +++++++----- tests/test-getlogin_r.c | 11 ++++++----- 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6df7b09a1e..2489838c20 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2025-04-18 Bruno Haible + + getlogin_r tests: Remove xalloc dependency. + * tests/test-getlogin.c (main): Don't assume the putenv argument is + unmodified. + * tests/test-getlogin_r.c: Do not include xalloc.h. + (main): Use a static rather than heap storage. + * modules/getlogin_r-tests (Depends-on): Remove xalloc. + (test_getlogin_LDADD): Remove @LIBINTL@. + 2025-04-17 Paul Eggert memset_explicit-tests: pacify -Wuse-after-free diff --git a/modules/getlogin_r-tests b/modules/getlogin_r-tests index 3cddb65584..8fefa059bc 100644 --- a/modules/getlogin_r-tests +++ b/modules/getlogin_r-tests @@ -6,11 +6,10 @@ tests/macros.h Depends-on: bool -xalloc configure.ac: Makefile.am: TESTS += test-getlogin_r check_PROGRAMS += test-getlogin_r -test_getlogin_r_LDADD = $(LDADD) @LIBINTL@ $(GETLOGIN_LIB) +test_getlogin_r_LDADD = $(LDADD) $(GETLOGIN_LIB) diff --git a/tests/test-getlogin.c b/tests/test-getlogin.c index 35ca3e0980..d2e006d5e1 100644 --- a/tests/test-getlogin.c +++ b/tests/test-getlogin.c @@ -43,11 +43,13 @@ main (void) test_getlogin_result (buf, err); /* Check that getlogin() does not merely return getenv ("LOGNAME"). */ - static char set_LOGNAME[] = "LOGNAME=ygvfibmslhkmvoetbrcegzwydorcke"; - putenv (set_LOGNAME); - buf = getlogin (); - ASSERT (!(buf != NULL - && strcmp (buf, set_LOGNAME + sizeof "LOGNAME") == 0)); + { + static char set_LOGNAME[] = "LOGNAME=ygvfibmslhkmvoetbrcegzwydorcke"; + putenv (set_LOGNAME); + buf = getlogin (); + ASSERT (!(buf != NULL + && strcmp (buf, "ygvfibmslhkmvoetbrcegzwydorcke") == 0)); + } return test_exit_status; } diff --git a/tests/test-getlogin_r.c b/tests/test-getlogin_r.c index e27e23da23..e8a438bf10 100644 --- a/tests/test-getlogin_r.c +++ b/tests/test-getlogin_r.c @@ -26,8 +26,6 @@ SIGNATURE_CHECK (getlogin_r, int, (char *, size_t)); #endif -#include "xalloc.h" - #include "test-getlogin.h" int @@ -72,9 +70,12 @@ main (void) } /* Check that getlogin_r() does not merely return getenv ("LOGNAME"). */ - putenv (xstrdup ("LOGNAME=ygvfibmslhkmvoetbrcegzwydorcke")); - err = getlogin_r (buf, sizeof buf); - ASSERT (!(err == 0 && strcmp (buf, "ygvfibmslhkmvoetbrcegzwydorcke") == 0)); + { + static char set_LOGNAME[] = "LOGNAME=ygvfibmslhkmvoetbrcegzwydorcke"; + putenv (set_LOGNAME); + err = getlogin_r (buf, sizeof buf); + ASSERT (!(err == 0 && strcmp (buf, "ygvfibmslhkmvoetbrcegzwydorcke") == 0)); + } return test_exit_status; } -- 2.39.5