Skip to content

Commit

Permalink
CUtlMemory_RawAllocator: fix the copy from method
Browse files Browse the repository at this point in the history
  • Loading branch information
Wend4r committed Nov 25, 2024
1 parent 7c24972 commit ff8c02c
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions public/tier1/utlmemory.h
Original file line number Diff line number Diff line change
Expand Up @@ -1296,12 +1296,20 @@ CUtlMemory_RawAllocator<T, I>::~CUtlMemory_RawAllocator()
template< class T, typename I >
void CUtlMemory_RawAllocator<T, I>::CopyFrom( const CUtlMemory_RawAllocator<T, I> &from )
{
m_pMemory = from.m_pMemory;
m_nAllocationCount = from.m_nAllocationCount;
const size_t nSize = from.m_nAllocationCount * sizeof(T);
size_t adjustedSize;
m_pMemory = (T*)CRawAllocator::Alloc( from.GetRawAllocatorType(), nSize, &adjustedSize );
m_nAllocationCount = ( I )( adjustedSize / sizeof(T) );

if ( m_pMemory )
{
memcpy( m_pMemory, from.m_pMemory, nSize );
}

m_nGrowSize = from.m_nGrowSize;

SetRawAllocatorType( from.GetRawAllocatorType() );
EnsureCapacity( from.m_nGrowSize );
EnsureCapacity( m_nGrowSize );
}

//-----------------------------------------------------------------------------
Expand Down

0 comments on commit ff8c02c

Please sign in to comment.