summaryrefslogtreecommitdiff
path: root/src/t_zset.c
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2011-05-15 17:28:06 +0200
committerantirez <antirez@gmail.com>2011-05-15 17:28:06 +0200
commitcb16b6c3899d0696a7e633c29f764e06b222b2fe (patch)
tree61812b8ab9e833ae98bf69d704b57f6b01844cf8 /src/t_zset.c
parentd070abe44cdc63ece3533d06986629b5b5c21ca8 (diff)
downloadredis-cb16b6c3899d0696a7e633c29f764e06b222b2fe.tar.gz
Fixed misuse of the new iterator semantics in ZUNIONSTORE
Diffstat (limited to 'src/t_zset.c')
-rw-r--r--src/t_zset.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/t_zset.c b/src/t_zset.c
index 8b1662091..1c55cb97a 100644
--- a/src/t_zset.c
+++ b/src/t_zset.c
@@ -1521,6 +1521,8 @@ void zunionInterGenericCommand(redisClient *c, robj *dstkey, int op) {
score = src[0].weight * zval.score;
for (j = 1; j < setnum; j++) {
+ /* It is not safe to access the hash we zset we are
+ * iterating, so explicitly check for equal object. */
if (src[j].subject == src[0].subject) {
value = zval.score*src[j].weight;
zunionInterAggregate(&score,value,aggregate);
@@ -1564,7 +1566,12 @@ void zunionInterGenericCommand(redisClient *c, robj *dstkey, int op) {
/* Because the inputs are sorted by size, it's only possible
* for sets at larger indices to hold this element. */
for (j = (i+1); j < setnum; j++) {
- if (zuiFind(&src[j],&zval,&value)) {
+ /* It is not safe to access the hash we zset we are
+ * iterating, so explicitly check for equal object. */
+ if(src[j].subject == src[i].subject) {
+ value = zval.score*src[j].weight;
+ zunionInterAggregate(&score,value,aggregate);
+ } else if (zuiFind(&src[j],&zval,&value)) {
value *= src[j].weight;
zunionInterAggregate(&score,value,aggregate);
}