From c4aace9003e29fc9becce292683dd09bdce7785c Mon Sep 17 00:00:00 2001 From: Pieter Noordhuis Date: Sat, 22 May 2010 21:49:36 +0200 Subject: [PATCH] fix compare function of ziplist to only load integer from ziplist when it is encoded as integer --- ziplist.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/ziplist.c b/ziplist.c index 3dd3c1e8..3dc534d3 100644 --- a/ziplist.c +++ b/ziplist.c @@ -374,18 +374,23 @@ unsigned int ziplistCompare(unsigned char *p, unsigned char *entry, unsigned int if (*p == ZIP_END) return 0; zlen = zipDecodeLength(p,&lensize); - if (zipTryEncoding(entry,&eval,&encoding)) { - /* Do integer compare */ - zval = zipLoadInteger(p+lensize,ZIP_ENCODING(p)); - return zval == eval; - } else { + if (ZIP_ENCODING(p) == ZIP_ENC_RAW) { /* Raw compare */ if (zlen == elen) { return memcmp(p+lensize,entry,elen) == 0; } else { return 0; } + } else { + if (zipTryEncoding(entry,&eval,&encoding)) { + /* Do integer compare */ + zval = zipLoadInteger(p+lensize,ZIP_ENCODING(p)); + return zval == eval; + } else { + /* Ziplist entry is integer encoded, but given entry is not. */ + } } + return 0; } /* Return length of ziplist. */ -- 2.47.2