X-Git-Url: https://git.saurik.com/redis.git/blobdiff_plain/ed9b544e10b84cd43348ddfab7068b610a5df1f7..76a41fb163b6e38845323e2b6a1269a31552c260:/sds.c diff --git a/sds.c b/sds.c index ca77a079..497d00f5 100644 --- a/sds.c +++ b/sds.c @@ -28,6 +28,8 @@ * POSSIBILITY OF SUCH DAMAGE. */ +#define SDS_ABORT_ON_OOM + #include "sds.h" #include #include @@ -138,7 +140,7 @@ sds sdscpylen(sds s, char *t, size_t len) { size_t totlen = sh->free+sh->len; if (totlen < len) { - s = sdsMakeRoomFor(s,len-totlen); + s = sdsMakeRoomFor(s,len-sh->len); if (s == NULL) return NULL; sh = (void*) (s-(sizeof(struct sdshdr))); totlen = sh->free+sh->len; @@ -275,11 +277,17 @@ sds *sdssplitlen(char *s, int len, char *sep, int seplen, int *count) { if (tokens == NULL) sdsOomAbort(); #endif if (seplen < 1 || len < 0 || tokens == NULL) return NULL; + if (len == 0) { + *count = 0; + return tokens; + } for (j = 0; j < (len-(seplen-1)); j++) { /* make sure there is room for the next element and the final one */ if (slots < elements+2) { + sds *newtokens; + slots *= 2; - sds *newtokens = zrealloc(tokens,sizeof(sds)*slots); + newtokens = zrealloc(tokens,sizeof(sds)*slots); if (newtokens == NULL) { #ifdef SDS_ABORT_ON_OOM sdsOomAbort();