summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPieter Noordhuis <pcnoordhuis@gmail.com>2010-11-04 13:26:22 +0100
committerPieter Noordhuis <pcnoordhuis@gmail.com>2010-11-04 13:26:22 +0100
commit9c4ee606d6cd04648ae4e34d42847ea65818448f (patch)
tree12c45f68fd8b9a66a80b34abe07cee5da865b68e
parent2e5e9a49fd1941296a6c94ca117e33bf2934bcfd (diff)
Use strchr in a loop rather than strstr
-rw-r--r--hiredis.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/hiredis.c b/hiredis.c
index 456067c..48ff7f9 100644
--- a/hiredis.c
+++ b/hiredis.c
@@ -162,11 +162,20 @@ static char *readBytes(redisReader *r, unsigned int bytes) {
return NULL;
}
+static char *seekNewline(char *s) {
+ /* Find pointer to \r\n without strstr */
+ while(s != NULL && s[0] != '\r' && s[1] != '\n')
+ s = strchr(s,'\r');
+ return s;
+}
+
static char *readLine(redisReader *r, int *_len) {
- char *p, *s = strstr(r->buf+r->pos,"\r\n");
+ char *p, *s;
int len;
+
+ p = r->buf+r->pos;
+ s = seekNewline(p);
if (s != NULL) {
- p = r->buf+r->pos;
len = s-(r->buf+r->pos);
r->pos += len+2; /* skip \r\n */
if (_len) *_len = len;
@@ -234,7 +243,7 @@ static int processBulkItem(redisReader *r) {
unsigned long bytelen;
p = r->buf+r->pos;
- s = strstr(p,"\r\n");
+ s = seekNewline(p);
if (s != NULL) {
p = r->buf+r->pos;
bytelen = s-(r->buf+r->pos)+2; /* include \r\n */