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 <yoav@redislabs.com>
This commit is contained in:
parent
d1b5767a82
commit
965356ae63
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user