diff options
Diffstat (limited to 'mysys/my_conio.c')
-rw-r--r-- | mysys/my_conio.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/mysys/my_conio.c b/mysys/my_conio.c index e381f9f23ef..def15674f26 100644 --- a/mysys/my_conio.c +++ b/mysys/my_conio.c @@ -2,8 +2,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. + the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -185,16 +184,19 @@ char* my_cgets(char *buffer, unsigned long clen, unsigned long* plen) } while (GetLastError() == ERROR_NOT_ENOUGH_MEMORY); + /* We go here on error reading the string (Ctrl-C for example) */ + if (!*plen) + result= NULL; /* purecov: inspected */ if (result != NULL) { - if (buffer[*plen - 2] == '\r') + if (*plen > 1 && buffer[*plen - 2] == '\r') { *plen= *plen - 2; } else { - if (buffer[*plen - 1] == '\r') + if (*plen > 0 && buffer[*plen - 1] == '\r') { char tmp[3]; int tmplen= sizeof(tmp); |