X-Git-Url: https://git.saurik.com/redis.git/blobdiff_plain/cc1cb7e5408291919922ded1aa3921f6b55c6307..d4d3a70da2c9be4c5aa67a0be735568dbe436568:/src/sds.c?ds=sidebyside diff --git a/src/sds.c b/src/sds.c index 7cb43962..8c754099 100644 --- a/src/sds.c +++ b/src/sds.c @@ -51,7 +51,11 @@ static void sdsOomAbort(void) { sds sdsnewlen(const void *init, size_t initlen) { struct sdshdr *sh; - sh = zmalloc(sizeof(struct sdshdr)+initlen+1); + if (init) { + sh = zmalloc(sizeof(struct sdshdr)+initlen+1); + } else { + sh = zcalloc(sizeof(struct sdshdr)+initlen+1); + } #ifdef SDS_ABORT_ON_OOM if (sh == NULL) sdsOomAbort(); #else @@ -59,10 +63,8 @@ sds sdsnewlen(const void *init, size_t initlen) { #endif sh->len = initlen; sh->free = 0; - if (initlen) { - if (init) memcpy(sh->buf, init, initlen); - else memset(sh->buf,0,initlen); - } + if (initlen && init) + memcpy(sh->buf, init, initlen); sh->buf[initlen] = '\0'; return (char*)sh->buf; }