Added check for fgets() return value.

This commit is contained in:
Tiiffi
2019-09-20 13:36:49 +03:00
parent 60fa0e42d8
commit ac31d9bc5a

View File

@ -746,10 +746,10 @@ int get_line(char *buffer, int bsize)
int ch, len; int ch, len;
fputs(">", stdout); fputs(">", stdout);
(void) fgets(buffer, bsize, stdin); char *ret = fgets(buffer, bsize, stdin);
if (ret == NULL) exit(EXIT_FAILURE);
if (buffer[0] == 0) if (buffer[0] == 0) global_connection_alive = 0;
global_connection_alive = 0;
// remove unwanted characters from the buffer // remove unwanted characters from the buffer
buffer[strcspn(buffer, "\r\n")] = '\0'; buffer[strcspn(buffer, "\r\n")] = '\0';