Fix synchronous readline "\n" handling.

Our function to read a line with a timeout handles newlines as requests
to refresh the timeout, however the code kept subtracting the buffer
size left every time a newline was received, for a bug in the loop
logic. Fixed by this commit.
This commit is contained in:
antirez 2015-08-05 16:51:50 +02:00
parent 55ba772703
commit 7ab3af0edc

View File

@ -138,6 +138,9 @@ ssize_t syncReadLine(int fd, char *ptr, ssize_t size, long long timeout) {
*ptr = '\0';
if (nread && *(ptr-1) == '\r') *(ptr-1) = '\0';
return nread;
} else {
/* Read again with a fresh timeout. */
continue;
}
} else {
*ptr++ = c;