]> git.saurik.com Git - redis.git/commitdiff
Fixed issue #516 (ZINTERSTORE mixing sets and zsets).
authorantirez <antirez@gmail.com>
Wed, 23 May 2012 09:02:38 +0000 (11:02 +0200)
committerantirez <antirez@gmail.com>
Wed, 23 May 2012 09:12:43 +0000 (11:12 +0200)
Weeks ago trying to fix an harmless GCC warning I introduced a bug in
the ziplist-encoded implementations of sorted sets.

The bug completely broke zuiNext() iterator, that is used in the
ZINTERSTORE and ZUNIONSTORE implementation, so those two commands are no
longer reliable starting from Redis version 2.4.12 and latest 2.6.0-RC
releases.

This commit fixes the problem and adds a regression test.

src/t_zset.c
tests/unit/type/zset.tcl

index 50ad8d433d2d7988dff5cd0829ad70c3638d5cca..4812709e19048c67acc25ab337fcc30d3e48ac8f 100644 (file)
@@ -1259,10 +1259,11 @@ int zuiNext(zsetopsrc *op, zsetopval *val) {
     if (op->type == REDIS_SET) {
         iterset *it = &op->iter.set;
         if (op->encoding == REDIS_ENCODING_INTSET) {
-            int64_t ell = val->ell;
+            int64_t ell;
 
             if (!intsetGet(it->is.is,it->is.ii,&ell))
                 return 0;
+            val->ell = ell;
             val->score = 1.0;
 
             /* Move to next element. */
index bab98854db8d5af8c3b593574de8fba9db0efb29..806f4c88be8e1294554dc63b8873b55e28d129cc 100644 (file)
@@ -524,6 +524,14 @@ start_server {tags {"zset"}} {
         r zrange out 0 -1 withscores
     } {neginf 0}
 
+    test {ZINTERSTORE #516 regression, mixed sets and ziplist zsets} {
+        r sadd one 100 101 102 103
+        r sadd two 100 200 201 202
+        r zadd three 1 500 1 501 1 502 1 503 1 100
+        r zinterstore to_here 3 one two three WEIGHTS 0 0 1
+        r zrange to_here 0 -1
+    } {100}
+
     proc stressers {encoding} {
         if {$encoding == "ziplist"} {
             # Little extra to allow proper fuzzing in the sorting stresser