]> git.saurik.com Git - redis.git/commitdiff
fix compare function of ziplist to only load integer from ziplist when it is encoded...
authorPieter Noordhuis <pcnoordhuis@gmail.com>
Sat, 22 May 2010 19:49:36 +0000 (21:49 +0200)
committerPieter Noordhuis <pcnoordhuis@gmail.com>
Sat, 29 May 2010 19:10:16 +0000 (21:10 +0200)
ziplist.c

index 3dd3c1e8fd798d5189705e9572bef48d68863d58..3dc534d31397ae1b7bd90ff40e8c3001267ead79 100644 (file)
--- 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 (*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;
         }
         /* 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. */
 }
 
 /* Return length of ziplist. */