On Fri, 30 Apr 2010 17:13:49 +0200 Bart wrote: BVA> > entry = itr_first; BVA> > for( ; entry; ++itr) { BVA> > // ... BVA> > if (condition) { BVA> > itr_remove; BVA> > continue; BVA> > } BVA> > // ... BVA> > } BVA> > BVA> BVA> If "++itr" accesses the memory itr points at, the above pseudocode will BVA> trigger an access to already freed memory (freed by itr_remove).
Sorry, I guess that should be itr_remove_current_item, as that's what it really does. As for the ++itr, let me try again.. entry = itr_first; for( ; entry; entry = itr_next) { // ... if (condition) { itr_remove_current_item; continue; } // ... } BVA> > I suppose another option is for remove to set a flag, and have ++itr not BVA> > actually advance if an item was removed... That should work for singly BVA> > linked lists to... Thoughts? BVA> BVA> Is the above approach in your opinion really simpler than what I proposed ? Yes, because it's doen internal to the iterator. Your solution would require anyone using the iterator to do the pointer juggling every time... ------------------------------------------------------------------------------ _______________________________________________ Net-snmp-coders mailing list Net-snmp-coders@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/net-snmp-coders