bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] yesno: Fix behavior difference in ENABLE_NLS


From: Tobias Stoeckmann
Subject: [PATCH] yesno: Fix behavior difference in ENABLE_NLS
Date: Mon, 23 Mar 2015 23:09:48 +0100

yesno behaves differently in a corner case depending on ENABLE_NLS.
Imagine an input of "y" followed by an EOF. On a terminal, it means
in general to type y followed by ^D once or twice.

If ENABLE_NLS is set, the input is considered to be "no", because the
last character is replaced with '\0'. The code assumes that there is
a newline, which doesn't have to be true. In this example, it overrides
the typed y before evaluating the line.

If ENABLE_NLS is not set, getchar() reads y and accepts it as "yes",
looping through more getchar() calls until reaching newline or EOF.

I recommend to just skip the '\0' assignment. Less code than checking
if newline is in place or not, because rpmatch() only checks first
character.
---
 lib/yesno.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/lib/yesno.c b/lib/yesno.c
index d5d9eec..0f7bf76 100644
--- a/lib/yesno.c
+++ b/lib/yesno.c
@@ -42,7 +42,6 @@ yesno (void)
     yes = false;
   else
     {
-      response[response_len - 1] = '\0';
       yes = (0 < rpmatch (response));
     }
 
-- 
2.3.3




reply via email to

[Prev in Thread] Current Thread [Next in Thread]