mirror of
https://github.com/fluencelabs/redis
synced 2025-03-30 22:31:03 +00:00
fix unexpected behavior on an out of range end index for LRANGE and LTRIM
This commit is contained in:
parent
4774a53b24
commit
f483ce5ffe
8
redis.c
8
redis.c
@ -5404,9 +5404,9 @@ static void lrangeCommand(redisClient *c) {
|
|||||||
if (start < 0) start = llen+start;
|
if (start < 0) start = llen+start;
|
||||||
if (end < 0) end = llen+end;
|
if (end < 0) end = llen+end;
|
||||||
if (start < 0) start = 0;
|
if (start < 0) start = 0;
|
||||||
if (end < 0) end = 0;
|
|
||||||
|
|
||||||
/* indexes sanity checks */
|
/* Invariant: start >= 0, so this test will be true when end < 0.
|
||||||
|
* The range is empty when start > end or start >= length. */
|
||||||
if (start > end || start >= llen) {
|
if (start > end || start >= llen) {
|
||||||
/* Out of range start or start > end result in empty list */
|
/* Out of range start or start > end result in empty list */
|
||||||
addReply(c,shared.emptymultibulk);
|
addReply(c,shared.emptymultibulk);
|
||||||
@ -5444,9 +5444,9 @@ static void ltrimCommand(redisClient *c) {
|
|||||||
if (start < 0) start = llen+start;
|
if (start < 0) start = llen+start;
|
||||||
if (end < 0) end = llen+end;
|
if (end < 0) end = llen+end;
|
||||||
if (start < 0) start = 0;
|
if (start < 0) start = 0;
|
||||||
if (end < 0) end = 0;
|
|
||||||
|
|
||||||
/* indexes sanity checks */
|
/* Invariant: start >= 0, so this test will be true when end < 0.
|
||||||
|
* The range is empty when start > end or start >= length. */
|
||||||
if (start > end || start >= llen) {
|
if (start > end || start >= llen) {
|
||||||
/* Out of range start or start > end result in empty list */
|
/* Out of range start or start > end result in empty list */
|
||||||
ltrim = llen;
|
ltrim = llen;
|
||||||
|
@ -340,6 +340,12 @@ start_server {
|
|||||||
create_$type mylist {1 2 3}
|
create_$type mylist {1 2 3}
|
||||||
assert_equal {1 2 3} [r lrange mylist -1000 1000]
|
assert_equal {1 2 3} [r lrange mylist -1000 1000]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test "LRANGE out of range negative end index - $type" {
|
||||||
|
create_$type mylist {1 2 3}
|
||||||
|
assert_equal {1} [r lrange mylist 0 -3]
|
||||||
|
assert_equal {} [r lrange mylist 0 -4]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
test {LRANGE against non existing key} {
|
test {LRANGE against non existing key} {
|
||||||
@ -369,6 +375,11 @@ start_server {
|
|||||||
assert_equal {1 2 3 4 5} [trim_list $type 0 10]
|
assert_equal {1 2 3 4 5} [trim_list $type 0 10]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test "LTRIM out of range negative end index - $type" {
|
||||||
|
assert_equal {1} [trim_list $type 0 -5]
|
||||||
|
assert_equal {} [trim_list $type 0 -6]
|
||||||
|
}
|
||||||
|
|
||||||
tags {"slow"} {
|
tags {"slow"} {
|
||||||
test "LTRIM stress testing - $type" {
|
test "LTRIM stress testing - $type" {
|
||||||
set mylist {}
|
set mylist {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user