summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--client/mysql.cc7
-rw-r--r--mysys/my_conio.c7
2 files changed, 11 insertions, 3 deletions
diff --git a/client/mysql.cc b/client/mysql.cc
index 368fce30d67..277b56328a6 100644
--- a/client/mysql.cc
+++ b/client/mysql.cc
@@ -1086,7 +1086,12 @@ static int read_and_execute(bool interactive)
something else is still in console input buffer
*/
} while (tmpbuf.alloced_length() <= clen);
- line= buffer.c_ptr();
+ /*
+ An empty line is returned from my_cgets when there's error reading :
+ Ctrl-c for example
+ */
+ if (line)
+ line= buffer.c_ptr();
#else /* OS2 */
buffer.length(0);
/* _cgets() expects the buffer size - 3 as the first byte */
diff --git a/mysys/my_conio.c b/mysys/my_conio.c
index 23b0c55e7a9..def15674f26 100644
--- a/mysys/my_conio.c
+++ b/mysys/my_conio.c
@@ -184,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);