check ziplist len to avoid crash on empty ziplist convert

This commit is contained in:
Malavan Sotheeswaran 2022-04-05 03:17:41 -07:00 committed by Vivek Saini
parent b73ece90f5
commit 8f02c51f2e

View File

@ -1191,6 +1191,7 @@ void zsetConvert(robj *zobj, int encoding) {
zs->dict = dictCreate(&zsetDictType,NULL); zs->dict = dictCreate(&zsetDictType,NULL);
zs->zsl = zslCreate(); zs->zsl = zslCreate();
if (ziplistLen(zl) > 0) {
eptr = ziplistIndex(zl,0); eptr = ziplistIndex(zl,0);
serverAssertWithInfo(NULL,zobj,eptr != NULL); serverAssertWithInfo(NULL,zobj,eptr != NULL);
sptr = ziplistNext(zl,eptr); sptr = ziplistNext(zl,eptr);
@ -1208,6 +1209,7 @@ void zsetConvert(robj *zobj, int encoding) {
serverAssert(dictAdd(zs->dict,ele,&node->score) == DICT_OK); serverAssert(dictAdd(zs->dict,ele,&node->score) == DICT_OK);
zzlNext(zl,&eptr,&sptr); zzlNext(zl,&eptr,&sptr);
} }
}
zfree(zobj->m_ptr); zfree(zobj->m_ptr);
zobj->m_ptr = zs; zobj->m_ptr = zs;