[Commits] Rev 3079: fixes for get_password(): in http://bazaar.launchpad.net/~maria-captains/maria/5.2/

serg at askmonty.org serg at askmonty.org
Tue Jan 3 00:05:48 EET 2012


At http://bazaar.launchpad.net/~maria-captains/maria/5.2/

------------------------------------------------------------
revno: 3079
revision-id: sergii at pisem.net-20120102220605-bt8hods7ws78oilt
parent: sergii at pisem.net-20111230125715-h4b0pfpf70wqkra4
committer: Sergei Golubchik <sergii at pisem.net>
branch nick: 5.2
timestamp: Mon 2012-01-02 23:06:05 +0100
message:
  fixes for get_password():
  
  1. on windows: don't hang when there's no console, that is, _getch() returns -1.
  2. on windows: _getch() returns an int, not char. to distinguish between (char)255 and (int)-1
  3. everywhere. isspace(pos[-1]) == ' ' never worked, isspace() returns a boolean, not a char.
     the never-worked loop was removed to preserve the existing behavior.
-------------- next part --------------
=== modified file 'libmysql/get_password.c'
--- a/libmysql/get_password.c	2011-12-02 15:26:43 +0000
+++ b/libmysql/get_password.c	2012-01-02 22:06:05 +0000
@@ -82,9 +82,9 @@ void get_tty_password_buff(const char *o
   _cputs(opt_message ? opt_message : "Enter password: ");
   for (;;)
   {
-    char tmp;
+    int tmp;
     tmp=_getch();
-    if (tmp == '\b' || (int) tmp == 127)
+    if (tmp == '\b' || tmp == 127)
     {
       if (pos != to)
       {
@@ -93,15 +93,13 @@ void get_tty_password_buff(const char *o
 	continue;
       }
     }
-    if (tmp == '\n' || tmp == '\r' || tmp == 3)
+    if (tmp == -1 || tmp == '\n' || tmp == '\r' || tmp == 3)
       break;
     if (iscntrl(tmp) || pos == end)
       continue;
     _cputs("*");
-    *(pos++) = tmp;
+    *(pos++) = (char)tmp;
   }
-  while (pos != to && isspace(pos[-1]) == ' ')
-    pos--;					/* Allow dummy space at end */
   *pos=0;
   _cputs("\n");
 }
@@ -148,8 +146,6 @@ static void get_password(char *to,uint l
     }
     *(pos++) = tmp;
   }
-  while (pos != to && isspace(pos[-1]) == ' ')
-    pos--;					/* Allow dummy space at end */
   *pos=0;
   return;
 }



More information about the commits mailing list