Commit 7ab3af0e authored by antirez's avatar antirez
Browse files

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.
parent 55ba7727
...@@ -138,6 +138,9 @@ ssize_t syncReadLine(int fd, char *ptr, ssize_t size, long long timeout) { ...@@ -138,6 +138,9 @@ ssize_t syncReadLine(int fd, char *ptr, ssize_t size, long long timeout) {
*ptr = '\0'; *ptr = '\0';
if (nread && *(ptr-1) == '\r') *(ptr-1) = '\0'; if (nread && *(ptr-1) == '\r') *(ptr-1) = '\0';
return nread; return nread;
} else {
/* Read again with a fresh timeout. */
continue;
} }
} else { } else {
*ptr++ = c; *ptr++ = c;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment