diff options
author | Matt Stancliff <matt@genges.com> | 2014-03-07 16:32:04 -0500 |
---|---|---|
committer | antirez <antirez@gmail.com> | 2014-03-11 11:10:09 +0100 |
commit | 14f77b343aa4bb3b513d56bda6a69b298e0c997f (patch) | |
tree | e7b5bc9a06414fa15fba393aa68b5c61f4bf3c14 | |
parent | 63fc5dc8b1c2af490deb8114ae66c82e1e8003f0 (diff) | |
download | redis-14f77b343aa4bb3b513d56bda6a69b298e0c997f.tar.gz |
Fix key extraction for z{union,inter}store
The previous implementation wasn't taking into account
the storage key in position 1 being a requirement (it
was only counting the source keys in positions 3 to N).
Fixes antirez/redis#1581
-rw-r--r-- | src/db.c | 18 |
1 files changed, 16 insertions, 2 deletions
@@ -993,9 +993,23 @@ int *zunionInterGetKeys(struct redisCommand *cmd,robj **argv, int argc, int *num *numkeys = 0; return NULL; } - keys = zmalloc(sizeof(int)*num); + + /* Keys in z{union,inter}store come from two places: + argv[1] = storage key, + argv[3...n] = keys to intersect */ + + /* (num+1) is (argv[2] + 1) to account for argv[1] too */ + keys = zmalloc(sizeof(int)*(num+1)); + + /* Add all key positions for argv[3...n] to keys[] */ for (i = 0; i < num; i++) keys[i] = 3+i; - *numkeys = num; + + /* Now add the argv[1] key position (the storage key target) + to our list of command positions containing keys. + num is the number of source keys, but we initialized + keys[] to size num+1, so keys[num] is safe and valid and okay. */ + keys[num] = 1; + *numkeys = num+1; /* Total keys = {union,inter} keys + storage key */ return keys; } |