"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/sds.c" between
redis-6.2-rc3.tar.gz and redis-6.2.0.tar.gz

About: redis is an advanced key-value store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets and sorted sets.

sds.c  (redis-6.2-rc3):sds.c  (redis-6.2.0)
skipping to change at line 114 skipping to change at line 114
void *sh; void *sh;
sds s; sds s;
char type = sdsReqType(initlen); char type = sdsReqType(initlen);
/* Empty strings are usually created in order to append. Use type 8 /* Empty strings are usually created in order to append. Use type 8
* since type 5 is not good at this. */ * since type 5 is not good at this. */
if (type == SDS_TYPE_5 && initlen == 0) type = SDS_TYPE_8; if (type == SDS_TYPE_5 && initlen == 0) type = SDS_TYPE_8;
int hdrlen = sdsHdrSize(type); int hdrlen = sdsHdrSize(type);
unsigned char *fp; /* flags pointer. */ unsigned char *fp; /* flags pointer. */
size_t usable; size_t usable;
assert(initlen + hdrlen + 1 > initlen); /* Catch size_t overflow */
sh = trymalloc? sh = trymalloc?
s_trymalloc_usable(hdrlen+initlen+1, &usable) : s_trymalloc_usable(hdrlen+initlen+1, &usable) :
s_malloc_usable(hdrlen+initlen+1, &usable); s_malloc_usable(hdrlen+initlen+1, &usable);
if (sh == NULL) return NULL; if (sh == NULL) return NULL;
if (init==SDS_NOINIT) if (init==SDS_NOINIT)
init = NULL; init = NULL;
else if (!init) else if (!init)
memset(sh, 0, hdrlen+initlen+1); memset(sh, 0, hdrlen+initlen+1);
s = (char*)sh+hdrlen; s = (char*)sh+hdrlen;
fp = ((unsigned char*)s)-1; fp = ((unsigned char*)s)-1;
skipping to change at line 246 skipping to change at line 247
char type, oldtype = s[-1] & SDS_TYPE_MASK; char type, oldtype = s[-1] & SDS_TYPE_MASK;
int hdrlen; int hdrlen;
size_t usable; size_t usable;
/* Return ASAP if there is enough space left. */ /* Return ASAP if there is enough space left. */
if (avail >= addlen) return s; if (avail >= addlen) return s;
len = sdslen(s); len = sdslen(s);
sh = (char*)s-sdsHdrSize(oldtype); sh = (char*)s-sdsHdrSize(oldtype);
newlen = (len+addlen); newlen = (len+addlen);
assert(newlen > len); /* Catch size_t overflow */
if (newlen < SDS_MAX_PREALLOC) if (newlen < SDS_MAX_PREALLOC)
newlen *= 2; newlen *= 2;
else else
newlen += SDS_MAX_PREALLOC; newlen += SDS_MAX_PREALLOC;
type = sdsReqType(newlen); type = sdsReqType(newlen);
/* Don't use type 5: the user is appending to the string and type 5 is /* Don't use type 5: the user is appending to the string and type 5 is
* not able to remember empty space, so sdsMakeRoomFor() must be called * not able to remember empty space, so sdsMakeRoomFor() must be called
* at every appending operation. */ * at every appending operation. */
if (type == SDS_TYPE_5) type = SDS_TYPE_8; if (type == SDS_TYPE_5) type = SDS_TYPE_8;
hdrlen = sdsHdrSize(type); hdrlen = sdsHdrSize(type);
assert(hdrlen + newlen + 1 > len); /* Catch size_t overflow */
if (oldtype==type) { if (oldtype==type) {
newsh = s_realloc_usable(sh, hdrlen+newlen+1, &usable); newsh = s_realloc_usable(sh, hdrlen+newlen+1, &usable);
if (newsh == NULL) return NULL; if (newsh == NULL) return NULL;
s = (char*)newsh+hdrlen; s = (char*)newsh+hdrlen;
} else { } else {
/* Since the header size changes, need to move the string forward, /* Since the header size changes, need to move the string forward,
* and can't use realloc */ * and can't use realloc */
newsh = s_malloc_usable(hdrlen+newlen+1, &usable); newsh = s_malloc_usable(hdrlen+newlen+1, &usable);
if (newsh == NULL) return NULL; if (newsh == NULL) return NULL;
memcpy((char*)newsh+hdrlen, s, len+1); memcpy((char*)newsh+hdrlen, s, len+1);
 End of changes. 3 change blocks. 
0 lines changed or deleted 3 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)