diff options
Diffstat (limited to 'src/sds.c')
-rw-r--r-- | src/sds.c | 34 |
1 files changed, 17 insertions, 17 deletions
@@ -49,9 +49,9 @@ sds sdsnewlen(const void *init, size_t initlen) { struct sdshdr *sh; if (init) { - sh = malloc(sizeof *sh+initlen+1); + sh = malloc(sizeof(struct sdshdr)+initlen+1); } else { - sh = calloc(sizeof *sh+initlen+1,1); + sh = calloc(sizeof(struct sdshdr)+initlen+1,1); } if (sh == NULL) return NULL; sh->len = initlen; @@ -100,7 +100,7 @@ void sdsfree(sds s) { * the output will be "6" as the string was modified but the logical length * remains 6 bytes. */ void sdsupdatelen(sds s) { - struct sdshdr *sh = (void*) (s-sizeof *sh);; + struct sdshdr *sh = (void*) (s-(sizeof(struct sdshdr))); int reallen = strlen(s); sh->free += (sh->len-reallen); sh->len = reallen; @@ -111,7 +111,7 @@ void sdsupdatelen(sds s) { * so that next append operations will not require allocations up to the * number of bytes previously available. */ void sdsclear(sds s) { - struct sdshdr *sh = (void*) (s-sizeof *sh);; + struct sdshdr *sh = (void*) (s-(sizeof(struct sdshdr))); sh->free += sh->len; sh->len = 0; sh->buf[0] = '\0'; @@ -130,13 +130,13 @@ sds sdsMakeRoomFor(sds s, size_t addlen) { if (free >= addlen) return s; len = sdslen(s); - sh = (void*) (s-sizeof *sh);; + sh = (void*) (s-(sizeof(struct sdshdr))); newlen = (len+addlen); if (newlen < SDS_MAX_PREALLOC) newlen *= 2; else newlen += SDS_MAX_PREALLOC; - newsh = realloc(sh, sizeof *newsh+newlen+1); + newsh = realloc(sh, sizeof(struct sdshdr)+newlen+1); if (newsh == NULL) return NULL; newsh->free = newlen - len; @@ -152,8 +152,8 @@ sds sdsMakeRoomFor(sds s, size_t addlen) { sds sdsRemoveFreeSpace(sds s) { struct sdshdr *sh; - sh = (void*) (s-sizeof *sh);; - sh = realloc(sh, sizeof *sh+sh->len+1); + sh = (void*) (s-(sizeof(struct sdshdr))); + sh = realloc(sh, sizeof(struct sdshdr)+sh->len+1); sh->free = 0; return sh->buf; } @@ -166,7 +166,7 @@ sds sdsRemoveFreeSpace(sds s) { * 4) The implicit null term. */ size_t sdsAllocSize(sds s) { - struct sdshdr *sh = (void*) (s-sizeof *sh);; + struct sdshdr *sh = (void*) (s-(sizeof(struct sdshdr))); return sizeof(*sh)+sh->len+sh->free+1; } @@ -195,7 +195,7 @@ size_t sdsAllocSize(sds s) { * sdsIncrLen(s, nread); */ void sdsIncrLen(sds s, int incr) { - struct sdshdr *sh = (void*) (s-sizeof *sh);; + struct sdshdr *sh = (void*) (s-(sizeof(struct sdshdr))); assert(sh->free >= incr); sh->len += incr; @@ -210,7 +210,7 @@ void sdsIncrLen(sds s, int incr) { * if the specified length is smaller than the current length, no operation * is performed. */ sds sdsgrowzero(sds s, size_t len) { - struct sdshdr *sh = (void*) (s-sizeof *sh); + struct sdshdr *sh = (void*)(s-(sizeof(struct sdshdr))); size_t totlen, curlen = sh->len; if (len <= curlen) return s; @@ -218,7 +218,7 @@ sds sdsgrowzero(sds s, size_t len) { if (s == NULL) return NULL; /* Make sure added region doesn't contain garbage */ - sh = (void*)(s-sizeof *sh); + sh = (void*)(s-(sizeof(struct sdshdr))); memset(s+curlen,0,(len-curlen+1)); /* also set trailing \0 byte */ totlen = sh->len+sh->free; sh->len = len; @@ -237,7 +237,7 @@ sds sdscatlen(sds s, const void *t, size_t len) { s = sdsMakeRoomFor(s,len); if (s == NULL) return NULL; - sh = (void*) (s-sizeof *sh);; + sh = (void*) (s-(sizeof(struct sdshdr))); memcpy(s+curlen, t, len); sh->len = curlen+len; sh->free = sh->free-len; @@ -264,13 +264,13 @@ sds sdscatsds(sds s, const sds t) { /* Destructively modify the sds string 's' to hold the specified binary * safe string pointed by 't' of length 'len' bytes. */ sds sdscpylen(sds s, const char *t, size_t len) { - struct sdshdr *sh = (void*) (s-sizeof *sh);; + struct sdshdr *sh = (void*) (s-(sizeof(struct sdshdr))); size_t totlen = sh->free+sh->len; if (totlen < len) { s = sdsMakeRoomFor(s,len-sh->len); if (s == NULL) return NULL; - sh = (void*) (s-sizeof *sh);; + sh = (void*) (s-(sizeof(struct sdshdr))); totlen = sh->free+sh->len; } memcpy(s, t, len); @@ -350,7 +350,7 @@ sds sdscatprintf(sds s, const char *fmt, ...) { * Output will be just "Hello World". */ void sdstrim(sds s, const char *cset) { - struct sdshdr *sh = (void*) (s-sizeof *sh);; + struct sdshdr *sh = (void*) (s-(sizeof(struct sdshdr))); char *start, *end, *sp, *ep; size_t len; @@ -382,7 +382,7 @@ void sdstrim(sds s, const char *cset) { * sdsrange(s,1,-1); => "ello World" */ void sdsrange(sds s, int start, int end) { - struct sdshdr *sh = (void*) (s-sizeof *sh);; + struct sdshdr *sh = (void*) (s-(sizeof(struct sdshdr))); size_t newlen, len = sdslen(s); if (len == 0) return; |