Don't care if object returned by object function is NULL

This commit is contained in:
Pieter Noordhuis 2010-11-24 15:05:25 +01:00
parent 1927c643da
commit 3d702d0bf1

View File

@ -236,9 +236,8 @@ static int processLineItem(redisReader *r) {
obj = (void*)(size_t)(cur->type); obj = (void*)(size_t)(cur->type);
} }
/* If there is no root yet, register this object as root. */ /* Set reply if this is the root object. */
if (r->reply == NULL) if (r->ridx == 0) r->reply = obj;
r->reply = obj;
moveToNextTask(r); moveToNextTask(r);
return 0; return 0;
} }
@ -251,6 +250,7 @@ static int processBulkItem(redisReader *r) {
char *p, *s; char *p, *s;
long len; long len;
unsigned long bytelen; unsigned long bytelen;
int success = 0;
p = r->buf+r->pos; p = r->buf+r->pos;
s = seekNewline(p); s = seekNewline(p);
@ -263,20 +263,23 @@ static int processBulkItem(redisReader *r) {
/* The nil object can always be created. */ /* The nil object can always be created. */
obj = r->fn ? r->fn->createNil(cur) : obj = r->fn ? r->fn->createNil(cur) :
(void*)REDIS_REPLY_NIL; (void*)REDIS_REPLY_NIL;
success = 1;
} else { } else {
/* Only continue when the buffer contains the entire bulk item. */ /* Only continue when the buffer contains the entire bulk item. */
bytelen += len+2; /* include \r\n */ bytelen += len+2; /* include \r\n */
if (r->pos+bytelen <= sdslen(r->buf)) { if (r->pos+bytelen <= sdslen(r->buf)) {
obj = r->fn ? r->fn->createString(cur,s+2,len) : obj = r->fn ? r->fn->createString(cur,s+2,len) :
(void*)REDIS_REPLY_STRING; (void*)REDIS_REPLY_STRING;
success = 1;
} }
} }
/* Proceed when obj was created. */ /* Proceed when obj was created. */
if (obj != NULL) { if (success) {
r->pos += bytelen; r->pos += bytelen;
if (r->reply == NULL)
r->reply = obj; /* Set reply if this is the root object. */
if (r->ridx == 0) r->reply = obj;
moveToNextTask(r); moveToNextTask(r);
return 0; return 0;
} }
@ -289,9 +292,12 @@ static int processMultiBulkItem(redisReader *r) {
void *obj; void *obj;
char *p; char *p;
long elements; long elements;
int root = 0;
if ((p = readLine(r,NULL)) != NULL) { if ((p = readLine(r,NULL)) != NULL) {
elements = strtol(p,NULL,10); elements = strtol(p,NULL,10);
root = (r->ridx == 0);
if (elements == -1) { if (elements == -1) {
obj = r->fn ? r->fn->createNil(cur) : obj = r->fn ? r->fn->createNil(cur) :
(void*)REDIS_REPLY_NIL; (void*)REDIS_REPLY_NIL;
@ -314,9 +320,8 @@ static int processMultiBulkItem(redisReader *r) {
} }
} }
/* Object was created, so we can always continue. */ /* Set reply if this is the root object. */
if (r->reply == NULL) if (root) r->reply = obj;
r->reply = obj;
return 0; return 0;
} }
return -1; return -1;