From b0d605c1d6bbf5746cc957946138108b928c88a1 Mon Sep 17 00:00:00 2001 From: Pieter Noordhuis Date: Thu, 23 Sep 2010 22:04:19 +0200 Subject: [PATCH] Add regression test and fix for >255 byte string entries --- src/ziplist.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/ziplist.c b/src/ziplist.c index 5254423d..4f44bd58 100644 --- a/src/ziplist.c +++ b/src/ziplist.c @@ -144,7 +144,7 @@ static unsigned int zipDecodeLength(unsigned char *p, unsigned int *lensize) { if (lensize) *lensize = 1; break; case ZIP_STR_14B: - len = ((p[0] & 0x3f) << 6) | p[1]; + len = ((p[0] & 0x3f) << 8) | p[1]; if (lensize) *lensize = 2; break; case ZIP_STR_32B: @@ -1125,6 +1125,25 @@ int main(int argc, char **argv) { ziplistRepr(zl); } + printf("Regression test for >255 byte strings:\n"); + { + char v1[257],v2[257]; + memset(v1,'x',256); + memset(v2,'y',256); + zl = ziplistNew(); + zl = ziplistPush(zl,(unsigned char*)v1,strlen(v1),ZIPLIST_TAIL); + zl = ziplistPush(zl,(unsigned char*)v2,strlen(v2),ZIPLIST_TAIL); + + /* Pop values again and compare their value. */ + p = ziplistIndex(zl,0); + assert(ziplistGet(p,&entry,&elen,&value)); + assert(strncmp(v1,entry,elen) == 0); + p = ziplistIndex(zl,1); + assert(ziplistGet(p,&entry,&elen,&value)); + assert(strncmp(v2,entry,elen) == 0); + printf("SUCCESS\n\n"); + } + printf("Create long list and check indices:\n"); { zl = ziplistNew(); -- 2.47.2