On 7 July 2017 at 13:54, Christopher Li <sparse@xxxxxxxxxxx> wrote: > On Fri, Jul 7, 2017 at 3:08 AM, Dibyendu Majumdar > <mobile@xxxxxxxxxxxxxxx> wrote: >> >> I will test this in my version but I believe that deleting entries in >> list->list[] is okay. Every time the next operation on the iterator is >> called, it checks whether its index in the node is still valid. As >> long as nodes are not deleted then it should work - but I need to >> prove it via a test case. > > As far as I can tell, your code will have the same bug. If > same list used in the outer loop and inner loop and inner > loop delete an entry. > > >> >> Here is my forward iterator next implementation: >> >> void *ptrlist_iter_next(struct ptr_list_iter *self) { >> if (self->__head == NULL) >> return NULL; >> self->__nr++; >> Lretry: >> if (self->__nr < self->__list->nr_) { >> return self->__list->list_[self->__nr]; >> } else if (self->__list->next_ != self->__head) { >> self->__list = self->__list->next_; >> self->__nr = 0; >> goto Lretry; >> } > > Let say __list has 8 entry. nr = 8. self->__nr = 3. > In the inner loop delete first 2 entry. Then the list[2:8] > will shift to list[0:6]. Now your self->__nr = 3 will > skip the next 2 entry because they move to list[1:3]. > Yes okay. So that means the inner loop cannot modify the list, as even adding an element will alter the order. Presumably this issue occurs when the same list is traversed recursively and the inner loop modifies the list. Was this usage always there is Sparse or is it a recent change? Regards Dibyendu -- To unsubscribe from this list: send the line "unsubscribe linux-sparse" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html