check ziplist len to avoid crash on empty ziplist convert
This commit is contained in:
parent
b73ece90f5
commit
8f02c51f2e
@ -1191,22 +1191,24 @@ void zsetConvert(robj *zobj, int encoding) {
|
|||||||
zs->dict = dictCreate(&zsetDictType,NULL);
|
zs->dict = dictCreate(&zsetDictType,NULL);
|
||||||
zs->zsl = zslCreate();
|
zs->zsl = zslCreate();
|
||||||
|
|
||||||
eptr = ziplistIndex(zl,0);
|
if (ziplistLen(zl) > 0) {
|
||||||
serverAssertWithInfo(NULL,zobj,eptr != NULL);
|
eptr = ziplistIndex(zl,0);
|
||||||
sptr = ziplistNext(zl,eptr);
|
serverAssertWithInfo(NULL,zobj,eptr != NULL);
|
||||||
serverAssertWithInfo(NULL,zobj,sptr != NULL);
|
sptr = ziplistNext(zl,eptr);
|
||||||
|
serverAssertWithInfo(NULL,zobj,sptr != NULL);
|
||||||
|
|
||||||
while (eptr != NULL) {
|
while (eptr != NULL) {
|
||||||
score = zzlGetScore(sptr);
|
score = zzlGetScore(sptr);
|
||||||
serverAssertWithInfo(NULL,zobj,ziplistGet(eptr,&vstr,&vlen,&vlong));
|
serverAssertWithInfo(NULL,zobj,ziplistGet(eptr,&vstr,&vlen,&vlong));
|
||||||
if (vstr == NULL)
|
if (vstr == NULL)
|
||||||
ele = sdsfromlonglong(vlong);
|
ele = sdsfromlonglong(vlong);
|
||||||
else
|
else
|
||||||
ele = sdsnewlen((char*)vstr,vlen);
|
ele = sdsnewlen((char*)vstr,vlen);
|
||||||
|
|
||||||
node = zslInsert(zs->zsl,score,ele);
|
node = zslInsert(zs->zsl,score,ele);
|
||||||
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);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user