From 9c4ee606d6cd04648ae4e34d42847ea65818448f Mon Sep 17 00:00:00 2001 From: Pieter Noordhuis Date: Thu, 4 Nov 2010 13:26:22 +0100 Subject: [PATCH] Use strchr in a loop rather than strstr --- hiredis.c | 15 ++++++++++++--- 1 file 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 */