From 965356ae63487dafeec378d1821201800b91307e Mon Sep 17 00:00:00 2001 From: Huang Zw Date: Wed, 24 Feb 2021 19:18:54 +0800 Subject: [PATCH] Fix quicklistDelRange dead code, delete range wrong (#8257) This commit fixes a bug in what's currently dead code in redis. In quicklistDelRange when delete entry from entry.offset to node tail, extent only need gte node->count - entry.offset, not node->count Co-authored-by: Yoav Steinberg --- src/quicklist.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/quicklist.c b/src/quicklist.c index c8517414c..7b7aa7839 100644 --- a/src/quicklist.c +++ b/src/quicklist.c @@ -999,7 +999,7 @@ int quicklistDelRange(quicklist *quicklist, const long start, * can just delete the entire node without ziplist math. */ delete_entire_node = 1; del = node->count; - } else if (entry.offset >= 0 && extent >= node->count) { + } else if (entry.offset >= 0 && extent + entry.offset >= node->count) { /* If deleting more nodes after this one, calculate delete based * on size of current node. */ del = node->count - entry.offset; @@ -2238,6 +2238,17 @@ int quicklistTest(int argc, char *argv[]) { quicklistRelease(ql); } + TEST("delete less than fill but across nodes") { + quicklist *ql = quicklistNew(-2, options[_i]); + quicklistSetFill(ql, 32); + for (int i = 0; i < 500; i++) + quicklistPushTail(ql, genstr("hello", i + 1), 32); + ql_verify(ql, 16, 500, 32, 20); + quicklistDelRange(ql, 60, 10); + ql_verify(ql, 16, 490, 32, 20); + quicklistRelease(ql); + } + TEST("delete negative 1 from 500 list") { quicklist *ql = quicklistNew(-2, options[_i]); quicklistSetFill(ql, 32);