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.
+2020-09-13 Ben Pfaff <blp@cs.stanford.edu>
+
+ 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 <eggert@cs.ucla.edu>
dfa: epsilon-closure tweaks (Bug#40634)
with this program; if not, see <https://www.gnu.org/licenses/>. */
#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 <config.h>
#endif
}
# 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);