From d2c2efefd4c0ed04c928a5fcd5ca858839c50ce7 Mon Sep 17 00:00:00 2001 From: GAMMACASE <31375974+GAMMACASE@users.noreply.github.com> Date: Sun, 3 Aug 2025 02:22:38 +0300 Subject: [PATCH] Correct CUtlLeanVector usages in CUtlRbTree & CUtlLinkedList --- public/tier1/utllinkedlist.h | 21 ++------------------- public/tier1/utlrbtree.h | 16 ++-------------- 2 files changed, 4 insertions(+), 33 deletions(-) diff --git a/public/tier1/utllinkedlist.h b/public/tier1/utllinkedlist.h index 7943155f..a2ccbd6e 100644 --- a/public/tier1/utllinkedlist.h +++ b/public/tier1/utllinkedlist.h @@ -422,29 +422,12 @@ I CUtlLinkedList::AllocInternal( bool multilist ) { Assert( m_Memory.IsValidIterator( m_LastAlloc ) || m_ElementCount == 0 ); - m_Memory.AddToTailGetPtr(); - - typename M::Iterator_t it = m_Memory.IsValidIterator( m_LastAlloc ) ? m_Memory.Next( m_LastAlloc ) : m_Memory.First(); - - if ( !m_Memory.IsValidIterator( it ) ) - { - MEM_ALLOC_CREDIT_CLASS(); - m_Memory.AddToTailGetPtr(); - - it = m_Memory.IsValidIterator( m_LastAlloc ) ? m_Memory.Next( m_LastAlloc ) : m_Memory.First(); - - Assert( m_Memory.IsValidIterator( it ) ); - if ( !m_Memory.IsValidIterator( it ) ) - { - ExecuteNTimes( 10, Warning( "CUtlLinkedList overflow! (exhausted memory allocator)\n" ) ); - return InvalidIndex(); - } - } + typename M::Iterator_t it = m_Memory.AddToTail(); // We can overflow before the utlmemory overflows, since S != I if ( !IndexInRange( m_Memory.GetIndex( it ) ) ) { - ExecuteNTimes( 10, Warning( "CUtlLinkedList overflow! (exhausted index range)\n" ) ); + Plat_FatalError( "CUtlLinkedList overflow! (exhausted index range)\n" ); return InvalidIndex(); } diff --git a/public/tier1/utlrbtree.h b/public/tier1/utlrbtree.h index b1e20086..ba287375 100644 --- a/public/tier1/utlrbtree.h +++ b/public/tier1/utlrbtree.h @@ -709,22 +709,10 @@ I CUtlRBTree::NewNode( bool bConstructElement ) if ( m_FirstFree == InvalidIndex() ) { Assert( m_Elements.IsValidIterator( m_LastAlloc ) || m_NumElements == 0 ); - typename M::Iterator_t it = m_Elements.IsValidIterator( m_LastAlloc ) ? m_Elements.Next( m_LastAlloc ) : m_Elements.First(); - if ( !m_Elements.IsValidIterator( it ) ) - { - MEM_ALLOC_CREDIT_CLASS(); - m_Elements.AddToTailGetPtr(); - it = m_Elements.IsValidIterator( m_LastAlloc ) ? m_Elements.Next( m_LastAlloc ) : m_Elements.First(); + MEM_ALLOC_CREDIT_CLASS(); + m_LastAlloc = m_Elements.AddToTail(); - Assert( m_Elements.IsValidIterator( it ) ); - if ( !m_Elements.IsValidIterator( it ) ) - { - Plat_FatalErrorFunc( "CUtlRBTree overflow with %u elements!\n", Count() ); - DebuggerBreak(); - } - } - m_LastAlloc = it; elem = m_Elements.GetIndex( m_LastAlloc ); Assert( m_Elements.IsValidIterator( m_LastAlloc ) ); }