diff options
author | antirez <antirez@gmail.com> | 2011-05-21 20:34:59 +0200 |
---|---|---|
committer | antirez <antirez@gmail.com> | 2011-05-21 20:34:59 +0200 |
commit | f447a7ebb4aabef7997f86bd991716b6633b903b (patch) | |
tree | 701ee6de620a3cb6fff8f4ace742ad16db51d69d | |
parent | 748a2da3e84893b9034d55372e332d3d1eebb129 (diff) | |
download | redis-f447a7ebb4aabef7997f86bd991716b6633b903b.tar.gz |
ZUNIONSTORE new iterator API fix backported into 2.2
-rw-r--r-- | src/t_zset.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/t_zset.c b/src/t_zset.c index be92e4521..c477fcbcb 100644 --- a/src/t_zset.c +++ b/src/t_zset.c @@ -735,10 +735,19 @@ void zunionInterGenericCommand(redisClient *c, robj *dstkey, int op) { /* because the zsets are sorted by size, its only possible * for sets at larger indices to hold this entry */ for (j = (i+1); j < setnum; j++) { - dictEntry *other = dictFind(src[j].dict,dictGetEntryKey(de)); - if (other) { - value = src[j].weight * zunionInterDictValue(other); + /* It is not safe to access the zset we are + * iterating, so explicitly check for equal object. */ + if (src[j].dict == src[i].dict) { + value = src[i].weight * zunionInterDictValue(de); zunionInterAggregate(&score,value,aggregate); + } else { + dictEntry *other; + + other = dictFind(src[j].dict,dictGetEntryKey(de)); + if (other) { + value = src[j].weight * zunionInterDictValue(other); + zunionInterAggregate(&score,value,aggregate); + } } } |