Skip to content

[BUG] quicklist iterator bug #12614

Description

@imchuncai

Function quicklistDelEntry() doesn't keep iterator behavior as expected. Here is the code:

    TEST("quicklistDelEntry()") {
        quicklist *ql = quicklistNew(-2, 1);
        quicklistPushTail(ql, "aa", 3);
        quicklistPushTail(ql, "bb", 3);
        quicklistPushTail(ql, "cc", 3);
        quicklistPushTail(ql, "dd", 3);
        quicklistPushTail(ql, "ee", 3);
        quicklistIter *iter = quicklistGetIteratorAtIdx(ql, AL_START_TAIL, 2);
        quicklistEntry entry;
        assert(quicklistNext(iter, &entry));
        quicklistDelEntry(iter, &entry);
        assert(quicklistNext(iter, &entry));
        assert(strcmp((char *)entry.value, "bb") == 0);
        quicklistReleaseIterator(iter);
        quicklistRelease(ql);
    }

I think function quicklistGetIteratorAtIdx() should be rewrite to meet the following assertion:

assert((quicklistIter->derection == AL_START_HEAD && quicklistIter->offset >= 0) || 
(quicklistIter->derection == AL_START_TAIL && quicklistIter->offset < 0))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions