X-Git-Url: https://git.saurik.com/redis.git/blobdiff_plain/a4d1ba9a73e459d68423c4da623f8cf1663c70ba..92b27fe946004935f0f29277d2a762c63af55ce3:/sds.c diff --git a/sds.c b/sds.c index d2b7543e..8d1edcb7 100644 --- a/sds.c +++ b/sds.c @@ -1,6 +1,6 @@ /* SDSLib, A C dynamic strings library * - * Copyright (c) 2006-2009, Salvatore Sanfilippo + * Copyright (c) 2006-2010, Salvatore Sanfilippo * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -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; @@ -157,7 +159,7 @@ sds sdscpy(sds s, char *t) { sds sdscatprintf(sds s, const char *fmt, ...) { va_list ap; char *buf, *t; - size_t buflen = 32; + size_t buflen = 16; while(1) { buf = zmalloc(buflen); @@ -275,6 +277,10 @@ 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) {