Fix UB, lose type safety.

This commit is contained in:
Bartosz Taudul 2018-04-03 16:45:55 +02:00
parent 2b8ce8341e
commit 3e93c615f7
2 changed files with 6 additions and 6 deletions

View File

@ -289,23 +289,23 @@ Profiler::DequeueStatus Profiler::Dequeue( moodycamel::ConsumerToken& token )
while( item != end ) while( item != end )
{ {
uint64_t ptr; uint64_t ptr;
const auto idx = MemRead( &item->hdr.idx ); const auto idx = MemRead<uint8_t>( &item->hdr.idx );
if( idx < (int)QueueType::Terminate ) if( idx < (int)QueueType::Terminate )
{ {
switch( (QueueType)idx ) switch( (QueueType)idx )
{ {
case QueueType::ZoneText: case QueueType::ZoneText:
ptr = MemRead( &item->zoneText.text ); ptr = MemRead<uint64_t>( &item->zoneText.text );
SendString( ptr, (const char*)ptr, QueueType::CustomStringData ); SendString( ptr, (const char*)ptr, QueueType::CustomStringData );
tracy_free( (void*)ptr ); tracy_free( (void*)ptr );
break; break;
case QueueType::Message: case QueueType::Message:
ptr = MemRead( &item->message.text ); ptr = MemRead<uint64_t>( &item->message.text );
SendString( ptr, (const char*)ptr, QueueType::CustomStringData ); SendString( ptr, (const char*)ptr, QueueType::CustomStringData );
tracy_free( (void*)ptr ); tracy_free( (void*)ptr );
break; break;
case QueueType::ZoneBeginAllocSrcLoc: case QueueType::ZoneBeginAllocSrcLoc:
ptr = MemRead( &item->zoneBegin.srcloc ); ptr = MemRead<uint64_t>( &item->zoneBegin.srcloc );
SendSourceLocationPayload( ptr ); SendSourceLocationPayload( ptr );
tracy_free( (void*)ptr ); tracy_free( (void*)ptr );
break; break;

View File

@ -9,7 +9,7 @@ namespace tracy
{ {
template<typename T> template<typename T>
tracy_force_inline T MemRead( T* ptr ) tracy_force_inline T MemRead( void* ptr )
{ {
T val; T val;
memcpy( &val, ptr, sizeof( T ) ); memcpy( &val, ptr, sizeof( T ) );
@ -17,7 +17,7 @@ tracy_force_inline T MemRead( T* ptr )
} }
template<typename T> template<typename T>
tracy_force_inline void MemWrite( T* ptr, T val ) tracy_force_inline void MemWrite( void* ptr, T val )
{ {
memcpy( ptr, &val, sizeof( T ) ); memcpy( ptr, &val, sizeof( T ) );
} }