X-Git-Url: https://git.saurik.com/redis.git/blobdiff_plain/eae33c1c813953e27dc37dfe7c3dcc246fda294f..8218db3dae220409f239a5a0adb47d106b178bf9:/src/sds.c diff --git a/src/sds.c b/src/sds.c index de620191..67e2d456 100644 --- a/src/sds.c +++ b/src/sds.c @@ -117,8 +117,8 @@ static sds sdsMakeRoomFor(sds s, size_t addlen) { } /* Grow the sds to have the specified length. Bytes that were not part of - * the original length of the sds will be set to NULL. */ -sds sdsgrowsafe(sds s, size_t len) { + * the original length of the sds will be set to zero. */ +sds sdsgrowzero(sds s, size_t len) { struct sdshdr *sh = (void*)(s-(sizeof(struct sdshdr))); size_t totlen, curlen = sh->len; @@ -128,7 +128,7 @@ sds sdsgrowsafe(sds s, size_t len) { /* Make sure added region doesn't contain garbage */ sh = (void*)(s-(sizeof(struct sdshdr))); - memset(s+curlen,0,(len-curlen+1)); /* also set trailing NULL byte */ + memset(s+curlen,0,(len-curlen+1)); /* also set trailing \0 byte */ totlen = sh->len+sh->free; sh->len = len; sh->free = totlen-sh->len; @@ -305,7 +305,10 @@ sds *sdssplitlen(char *s, int len, char *sep, int seplen, int *count) { #ifdef SDS_ABORT_ON_OOM if (tokens == NULL) sdsOomAbort(); #endif - if (seplen < 1 || len < 0 || tokens == NULL) return NULL; + if (seplen < 1 || len < 0 || tokens == NULL) { + *count = 0; + return NULL; + } if (len == 0) { *count = 0; return tokens; @@ -360,6 +363,7 @@ cleanup: int i; for (i = 0; i < elements; i++) sdsfree(tokens[i]); zfree(tokens); + *count = 0; return NULL; } #endif