diff options
Diffstat (limited to 'mysys')
-rw-r--r-- | mysys/my_conio.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/mysys/my_conio.c b/mysys/my_conio.c index 1ea1f7a820a..b78966446ee 100644 --- a/mysys/my_conio.c +++ b/mysys/my_conio.c @@ -187,15 +187,19 @@ char* my_cgets(char *buffer, size_t clen, size_t* plen) while (GetLastError() == ERROR_NOT_ENOUGH_MEMORY); *plen= plen_res; + /* 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); |