@@ -1191,24 +1191,26 @@ void zsetConvert(robj *zobj, int encoding) {
11911191 zs->dict = dictCreate (&zsetDictType,NULL );
11921192 zs->zsl = zslCreate ();
11931193
1194- eptr = ziplistIndex (zl,0 );
1195- serverAssertWithInfo (NULL ,zobj,eptr != NULL );
1196- sptr = ziplistNext (zl,eptr);
1197- serverAssertWithInfo (NULL ,zobj,sptr != NULL );
1198-
1199- while (eptr != NULL ) {
1200- score = zzlGetScore (sptr);
1201- serverAssertWithInfo (NULL ,zobj,ziplistGet (eptr,&vstr,&vlen,&vlong));
1202- if (vstr == NULL )
1203- ele = sdsfromlonglong (vlong);
1204- else
1205- ele = sdsnewlen ((char *)vstr,vlen);
1194+ if (ziplistLen (zl) > 0 ) {
1195+ eptr = ziplistIndex (zl,0 );
1196+ serverAssertWithInfo (NULL ,zobj,eptr != NULL );
1197+ sptr = ziplistNext (zl,eptr);
1198+ serverAssertWithInfo (NULL ,zobj,sptr != NULL );
12061199
1207- node = zslInsert (zs->zsl ,score,ele);
1208- serverAssert (dictAdd (zs->dict ,ele,&node->score ) == DICT_OK);
1209- zzlNext (zl,&eptr,&sptr);
1200+ while (eptr != NULL ) {
1201+ score = zzlGetScore (sptr);
1202+ serverAssertWithInfo (NULL ,zobj,ziplistGet (eptr,&vstr,&vlen,&vlong));
1203+ if (vstr == NULL )
1204+ ele = sdsfromlonglong (vlong);
1205+ else
1206+ ele = sdsnewlen ((char *)vstr,vlen);
1207+
1208+ node = zslInsert (zs->zsl ,score,ele);
1209+ serverAssert (dictAdd (zs->dict ,ele,&node->score ) == DICT_OK);
1210+ zzlNext (zl,&eptr,&sptr);
1211+ }
12101212 }
1211-
1213+
12121214 zfree (zobj->m_ptr );
12131215 zobj->m_ptr = zs;
12141216 zobj->encoding = OBJ_ENCODING_SKIPLIST;
0 commit comments