summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--hiredis.c11
-rw-r--r--test.c11
2 files changed, 21 insertions, 1 deletions
diff --git a/hiredis.c b/hiredis.c
index ffdf027..f0d78a0 100644
--- a/hiredis.c
+++ b/hiredis.c
@@ -164,8 +164,17 @@ static char *readBytes(redisReader *r, unsigned int bytes) {
static char *seekNewline(char *s) {
/* Find pointer to \r\n without strstr */
- while(s != NULL && s[0] != '\r' && s[1] != '\n')
+ while (s != NULL) {
s = strchr(s,'\r');
+ if (s != NULL) {
+ if (s[1] == '\n')
+ break;
+ else
+ s++;
+ } else {
+ break;
+ }
+ }
return s;
}
diff --git a/test.c b/test.c
index 995456e..c82ea51 100644
--- a/test.c
+++ b/test.c
@@ -219,6 +219,17 @@ static void test_reply_reader() {
ret = redisReplyReaderGetReply(reader,&reply);
test_cond(ret == REDIS_OK && reply == (void*)REDIS_REPLY_STATUS);
redisReplyReaderFree(reader);
+
+ test("Works when a single newline (\\r\\n) covers two calls to feed: ");
+ reader = redisReplyReaderCreate();
+ redisReplyReaderSetReplyObjectFunctions(reader,NULL);
+ redisReplyReaderFeed(reader,(char*)"+OK\r",4);
+ ret = redisReplyReaderGetReply(reader,&reply);
+ assert(ret == REDIS_OK && reply == NULL);
+ redisReplyReaderFeed(reader,(char*)"\n",1);
+ ret = redisReplyReaderGetReply(reader,&reply);
+ test_cond(ret == REDIS_OK && reply == (void*)REDIS_REPLY_STATUS);
+ redisReplyReaderFree(reader);
}
static void test_throughput() {