[sldev] [VIEWER] Daring construct? (is this safe?)

nik at terminaldischarge.net nik at terminaldischarge.net
Wed Sep 26 09:22:31 PDT 2007


should be

it will use the value of gi then increments it. So should be fine.

>
> Seen in llgroupmgr.cpp at 1330
>
> mGroups is a std::map.
>
> Question is if the mGroups.erase(gi++); is safe or depends on
> order of evaluation and/or possibly accesses freed memory
> (doing the increment after the erase)?
>
> (I'm seeing this in a lot of places ... grep erase\(.*++\);   ).
>
>
>
> // get rid of groups that aren't observed
> for (group_iter gi = mGroups.begin(); gi != mGroups.end() &&
> mGroups.size() > MAX_CACHED_GROUPS / 2; )
> {
> 	observer_iter oi = mObservers.find(gi->first);
> 	if (oi == mObservers.end())
> 	{
> 		// not observed
> 		LLGroupMgrGroupData* group_datap = gi->second;
> 		delete group_datap;
> 		mGroups.erase(gi++);
-- on first loop gi is evaluated as begin.
but also increments it. its the same as doing

mGroups.erase(gi);
gi++;

> 	}
> 	else
> 	{
> 		++gi;
> 	}
> }
>
>
> --
> Second Life from the inside out:
> http://nicholaz-beresford.blogspot.com/
> _______________________________________________
> Click here to unsubscribe or manage your list subscription:
> /index.html
>




More information about the SLDev mailing list