]> Savannah Git Hosting - gnulib.git/commitdiff
getlogin tests: Avoid writing to a literal string.
authorBruno Haible <bruno@clisp.org>
Sun, 13 Apr 2025 21:17:06 +0000 (23:17 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 13 Apr 2025 21:17:06 +0000 (23:17 +0200)
* tests/test-getlogin.c: Include xalloc.h.
(main): Pass a writable string to putenv().
* modules/getlogin-tests (Depends-on): Add xalloc.
(Makefile.am): Link the program with libintl when needed.

ChangeLog
modules/getlogin-tests
tests/test-getlogin.c

index c766cc9cca7b24ead8055ad84d9e71055c02b730..1547bed51e647814374d5fe308a0afd47b931ab5 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2025-04-13  Bruno Haible  <bruno@clisp.org>
+
+       getlogin tests: Avoid writing to a literal string.
+       * tests/test-getlogin.c: Include xalloc.h.
+       (main): Pass a writable string to putenv().
+       * modules/getlogin-tests (Depends-on): Add xalloc.
+       (Makefile.am): Link the program with libintl when needed.
+
 2025-04-13  Bruno Haible  <bruno@clisp.org>
 
        vasnprintf: Optimize last commit.
index 8637b2ea7e06ecdb40e5bf83fe4ce14ff93e5ae9..6484ffe251585b431cea14ea48abe9e100f6d2a4 100644 (file)
@@ -6,10 +6,11 @@ tests/macros.h
 
 Depends-on:
 bool
+xalloc
 
 configure.ac:
 
 Makefile.am:
 TESTS += test-getlogin
 check_PROGRAMS += test-getlogin
-test_getlogin_LDADD = $(LDADD) $(GETLOGIN_LIB)
+test_getlogin_LDADD = $(LDADD) @LIBINTL@ $(GETLOGIN_LIB)
index 431844bd715a6cdce90b09f68126657a01f5e446..11f67de5427882cd7fcb13c33763b60abeff0241 100644 (file)
 
 #include <config.h>
 
+/* Specification.  */
 #include <unistd.h>
 
 #include "signature.h"
 SIGNATURE_CHECK (getlogin, char *, (void));
 
+#include "xalloc.h"
+
 #include "test-getlogin.h"
 
 int
@@ -42,7 +45,7 @@ main (void)
   test_getlogin_result (buf, err);
 
   /* Check that getlogin() does not merely return getenv ("LOGNAME").  */
-  putenv ("LOGNAME=ygvfibmslhkmvoetbrcegzwydorcke");
+  putenv (xstrdup ("LOGNAME=ygvfibmslhkmvoetbrcegzwydorcke"));
   buf = getlogin ();
   ASSERT (!(buf != NULL
             && strcmp (buf, "ygvfibmslhkmvoetbrcegzwydorcke") == 0));