* 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>
+
+ 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.
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)
#include <config.h>
+/* Specification. */
#include <unistd.h>
#include "signature.h"
SIGNATURE_CHECK (getlogin, char *, (void));
+#include "xalloc.h"
+
#include "test-getlogin.h"
int
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));