From: Pieter Noordhuis Date: Fri, 5 Nov 2010 16:24:48 +0000 (+0100) Subject: Update hiredis X-Git-Url: https://git.saurik.com/redis.git/commitdiff_plain/57c9babd819339544a8c7447a7cbae7e70f64678?ds=inline Update hiredis --- diff --git a/deps/hiredis/hiredis.c b/deps/hiredis/hiredis.c index 66789d0f..f0d78a0d 100644 --- a/deps/hiredis/hiredis.c +++ b/deps/hiredis/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; } @@ -424,7 +433,7 @@ char *redisReplyReaderGetError(void *reader) { return r->error; } -void redisReplyReaderFeed(void *reader, char *buf, int len) { +void redisReplyReaderFeed(void *reader, char *buf, size_t len) { redisReader *r = reader; /* Copy the provided buffer. */ diff --git a/deps/hiredis/hiredis.h b/deps/hiredis/hiredis.h index 0a6a9a10..cb25b363 100644 --- a/deps/hiredis/hiredis.h +++ b/deps/hiredis/hiredis.h @@ -115,7 +115,7 @@ int redisReplyReaderSetReplyObjectFunctions(void *reader, redisReplyObjectFuncti void *redisReplyReaderGetObject(void *reader); char *redisReplyReaderGetError(void *reader); void redisReplyReaderFree(void *ptr); -void redisReplyReaderFeed(void *reader, char *buf, int len); +void redisReplyReaderFeed(void *reader, char *buf, size_t len); int redisReplyReaderGetReply(void *reader, void **reply); /* Functions to format a command according to the protocol. */ diff --git a/deps/hiredis/test.c b/deps/hiredis/test.c index 995456ed..d23bc188 100644 --- a/deps/hiredis/test.c +++ b/deps/hiredis/test.c @@ -5,6 +5,7 @@ #include #include #include +#include #include "hiredis.h" @@ -219,6 +220,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() {