mirror of
https://github.com/nillerusr/source-engine.git
synced 2025-02-05 11:44:14 +00:00
utlvector: fix undefined behavior
This commit is contained in:
parent
de6f256299
commit
88e720bfc1
@ -182,6 +182,7 @@ public:
|
|||||||
|
|
||||||
// Purges the list and calls delete on each element in it.
|
// Purges the list and calls delete on each element in it.
|
||||||
void PurgeAndDeleteElements();
|
void PurgeAndDeleteElements();
|
||||||
|
void PurgeAndDeleteElementsArray();
|
||||||
|
|
||||||
// Compacts the vector to the number of elements actually in use
|
// Compacts the vector to the number of elements actually in use
|
||||||
void Compact();
|
void Compact();
|
||||||
@ -475,6 +476,18 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PurgeAndDeleteElementsArray()
|
||||||
|
{
|
||||||
|
if ( m_pData != StaticData() )
|
||||||
|
{
|
||||||
|
for( int i=0; i < m_pData->m_Size; i++ )
|
||||||
|
{
|
||||||
|
delete[] Element(i);
|
||||||
|
}
|
||||||
|
RemoveAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void FastRemove( int elem )
|
void FastRemove( int elem )
|
||||||
{
|
{
|
||||||
Assert( IsValidIndex(elem) );
|
Assert( IsValidIndex(elem) );
|
||||||
@ -1413,6 +1426,17 @@ inline void CUtlVector<T, A>::PurgeAndDeleteElements()
|
|||||||
Purge();
|
Purge();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template< typename T, class A >
|
||||||
|
inline void CUtlVector<T, A>::PurgeAndDeleteElementsArray()
|
||||||
|
{
|
||||||
|
for( int i=0; i < m_Size; i++ )
|
||||||
|
{
|
||||||
|
delete[] Element(i);
|
||||||
|
}
|
||||||
|
RemoveAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
template< typename T, class A >
|
template< typename T, class A >
|
||||||
inline void CUtlVector<T, A>::Compact()
|
inline void CUtlVector<T, A>::Compact()
|
||||||
{
|
{
|
||||||
@ -1441,23 +1465,16 @@ void CUtlVector<T, A>::Validate( CValidator &validator, char *pchName )
|
|||||||
}
|
}
|
||||||
#endif // DBGFLAG_VALIDATE
|
#endif // DBGFLAG_VALIDATE
|
||||||
|
|
||||||
// A vector class for storing pointers, so that the elements pointed to by the pointers are deleted
|
|
||||||
// on exit.
|
|
||||||
template<class T> class CUtlVectorAutoPurge : public CUtlVector< T, CUtlMemory< T, int> >
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
~CUtlVectorAutoPurge( void )
|
|
||||||
{
|
|
||||||
this->PurgeAndDeleteElements();
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
// easy string list class with dynamically allocated strings. For use with V_SplitString, etc.
|
// easy string list class with dynamically allocated strings. For use with V_SplitString, etc.
|
||||||
// Frees the dynamic strings in destructor.
|
// Frees the dynamic strings in destructor.
|
||||||
class CUtlStringList : public CUtlVectorAutoPurge< char *>
|
class CUtlStringList : public CUtlVector< char*, CUtlMemory< char*, int > >
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
~CUtlStringList( void )
|
||||||
|
{
|
||||||
|
PurgeAndDeleteElementsArray();
|
||||||
|
}
|
||||||
|
|
||||||
void CopyAndAddToTail( char const *pString ) // clone the string and add to the end
|
void CopyAndAddToTail( char const *pString ) // clone the string and add to the end
|
||||||
{
|
{
|
||||||
char *pNewStr = new char[1 + strlen( pString )];
|
char *pNewStr = new char[1 + strlen( pString )];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user