From: Pieter Noordhuis Date: Mon, 17 Jan 2011 10:10:30 +0000 (+0100) Subject: Test for ranges where min > max X-Git-Url: https://git.saurik.com/redis.git/commitdiff_plain/8e1b327706ca39f9efb8967653b365ca81a52425?ds=inline Test for ranges where min > max --- diff --git a/src/t_zset.c b/src/t_zset.c index 0e7d726b..99fe6a8b 100644 --- a/src/t_zset.c +++ b/src/t_zset.c @@ -196,6 +196,10 @@ static int zslValueInRange(double value, zrangespec *spec) { int zslIsInRange(zskiplist *zsl, zrangespec *range) { zskiplistNode *x; + /* Test for ranges that will always be empty. */ + if (range->min > range->max || + (range->min == range->max && (range->minex || range->maxex))) + return 0; x = zsl->tail; if (x == NULL || !zslValueInMinRange(x->score,range)) return 0; diff --git a/tests/unit/type/zset.tcl b/tests/unit/type/zset.tcl index a54ff37b..fdeebd2f 100644 --- a/tests/unit/type/zset.tcl +++ b/tests/unit/type/zset.tcl @@ -233,12 +233,16 @@ start_server {tags {"zset"}} { r zrem zset g # inclusive + assert_equal {} [r zrangebyscore zset 4 2] assert_equal {} [r zrangebyscore zset 6 +inf] assert_equal {} [r zrangebyscore zset -inf -6] assert_equal {} [r zrevrangebyscore zset +inf 6] assert_equal {} [r zrevrangebyscore zset -6 -inf] # exclusive + assert_equal {} [r zrangebyscore zset (4 (2] + assert_equal {} [r zrangebyscore zset 2 (2] + assert_equal {} [r zrangebyscore zset (2 2] assert_equal {} [r zrangebyscore zset (6 (+inf] assert_equal {} [r zrangebyscore zset (-inf (-6] assert_equal {} [r zrevrangebyscore zset (+inf (6]