From 1e737bb51ffc7e75e56758fab3340a7abc4d8cd4 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Sun, 13 Sep 2020 20:59:53 +0200 Subject: [PATCH] getpass: Check for nonnull prompt argument while avoiding warnings. The prompt parameter to getpass() is declared as nonnull (using a GCC nonnull attribute). Gnulib contains two implementations of this function, one for POSIX, one for Windows. The Windows implementation checked for a nonnull prompt, which caused a GCC warning. This commit fixes that by avoiding the nonnull attribute when building getpass.c. The POSIX implementation did not check for a nonnull prompt. This commit increases the robustness by adding such a check. * lib/getpass.c (_GL_ARG_NONNULL): Define to empty. (getpass) [!_WIN32]: Print prompt only if nonnull. --- ChangeLog | 6 ++++++ lib/getpass.c | 12 +++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 66aec61cb2..62e1f17d32 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2020-09-13 Ben Pfaff + + getpass: Check for nonnull prompt argument while avoiding warnings. + * lib/getpass.c (_GL_ARG_NONNULL): Define to empty. + (getpass) [!_WIN32]: Print prompt only if nonnull. + 2020-09-12 Paul Eggert dfa: epsilon-closure tweaks (Bug#40634) diff --git a/lib/getpass.c b/lib/getpass.c index 3b0552ec58..ca528fdc09 100644 --- a/lib/getpass.c +++ b/lib/getpass.c @@ -16,6 +16,9 @@ with this program; if not, see . */ #ifndef _LIBC +/* Don't use __attribute__ __nonnull__ in this compilation unit. Otherwise gcc + warns for the null checks on 'prompt' below. */ +# define _GL_ARG_NONNULL(params) # include #endif @@ -124,9 +127,12 @@ getpass (const char *prompt) } # endif - /* Write the prompt. */ - fputs_unlocked (prompt, out); - fflush_unlocked (out); + if (prompt) + { + /* Write the prompt. */ + fputs_unlocked (prompt, out); + fflush_unlocked (out); + } /* Read the password. */ nread = getline (&buf, &bufsize, in); -- 2.39.5