- newlen = (len+addlen);
- newfree = ((addlen*2) > USHRT_MAX) ? USHRT_MAX : (addlen*2);
- if (newlen+newfree >= USHRT_MAX || sh->_len == USHRT_MAX) {
- if (sh->_len == USHRT_MAX) {
- newsh = zrealloc(sh, sizeof(struct sdshdr)+newlen+1+newfree);
- } else {
- newsh = zmalloc(sizeof(struct sdshdr)+newlen+1+newfree);
- if (!newsh) return NULL;
- memcpy(newsh->buf,sh->buf,len);
- newsh->buf[len] = '\0';
- zfree(((char*)sh)+sizeof(int));
- }
-#ifdef SDS_ABORT_ON_OOM
- if (newsh == NULL) sdsOomAbort();
-#else
- if (newsh == NULL) return NULL;
-#endif
- newsh->_len = USHRT_MAX;
- newsh->free = newfree;
- newsh->len = newlen;
- } else {
- newsh = zrealloc(((char*)sh)+sizeof(int), sizeof(int)+newlen+1+newfree);
- newsh = (struct sdshdr*) (((char*)newsh)-sizeof(int));
+ newlen = (len+addlen)*2;
+ newsh = zrealloc(sh, sizeof(struct sdshdr)+newlen+1);