Those places are all bogus and should be considered bugs.  If nothing is
deleted from the tree then it might work in most cases, but it's the
wrong iteration pattern.

Yahn

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Tim Baker
Sent: Monday, April 14, 2008 2:38 PM
To: [email protected]
Subject: [hlcoders] Proper way to iterate a CUtlDict?

I was tracking down a crash in ai_speech.cpp
CConceptHistoriesDataOps::Save.
It looks as though m_ConceptHistories is not being iterated over
properly?

CUtlDict< ConceptHistory_t, int > *ch = ...;
int count = ch->Count();
for (int i = 0; i < count; i++ ) { ... }

CUtlDict uses a CUtlRBTree for storage and that class has methods
for testing whether an index is valid or not.  Nodes in the tree aren't
stored like an array, so going from 0->count seems wrong.  The correct
way seems to be this:

for ( int i = ch->First(); i != ch->InvalidIndex(); i = ch->Next( i ) )

But there are so many places in the code that iterate over CUtlDicts
from 0->count I'm wondering what is going on here.

_______________________________________________
To unsubscribe, edit your list preferences, or view the list archives,
please visit:
http://list.valvesoftware.com/mailman/listinfo/hlcoders


_______________________________________________
To unsubscribe, edit your list preferences, or view the list archives, please 
visit:
http://list.valvesoftware.com/mailman/listinfo/hlcoders

Reply via email to