diff --git a/client/TracyProfiler.cpp b/client/TracyProfiler.cpp index 6e89d3de..0aa1326a 100644 --- a/client/TracyProfiler.cpp +++ b/client/TracyProfiler.cpp @@ -2236,16 +2236,17 @@ void Profiler::SendSourceLocationPayload( uint64_t _ptr ) MemWrite( &item.hdr.type, QueueType::SourceLocationPayload ); MemWrite( &item.stringTransfer.ptr, _ptr ); - const auto len = *((uint32_t*)ptr); - assert( len <= std::numeric_limits::max() ); - assert( len > 4 ); - const auto l16 = uint16_t( len - 4 ); + uint16_t len; + memcpy( &len, ptr, sizeof( len ) ); + assert( len > 2 ); + len -= 2; + ptr += 2; - NeedDataSize( QueueDataSize[(int)QueueType::SourceLocationPayload] + sizeof( l16 ) + l16 ); + NeedDataSize( QueueDataSize[(int)QueueType::SourceLocationPayload] + sizeof( len ) + len ); AppendDataUnsafe( &item, QueueDataSize[(int)QueueType::SourceLocationPayload] ); - AppendDataUnsafe( &l16, sizeof( l16 ) ); - AppendDataUnsafe( ptr + 4, l16 ); + AppendDataUnsafe( &len, sizeof( len ) ); + AppendDataUnsafe( ptr, len ); } void Profiler::SendCallstackPayload( uint64_t _ptr ) diff --git a/client/TracyProfiler.hpp b/client/TracyProfiler.hpp index db9deb45..1507418f 100644 --- a/client/TracyProfiler.hpp +++ b/client/TracyProfiler.hpp @@ -477,7 +477,7 @@ public: // Allocated source location data layout: - // 4b payload size + // 2b payload size // 4b color // 4b source line // fsz function name @@ -503,18 +503,20 @@ public: static tracy_force_inline uint64_t AllocSourceLocation( uint32_t line, const char* source, size_t sourceSz, const char* function, size_t functionSz, const char* name, size_t nameSz ) { - const uint32_t sz = uint32_t( 4 + 4 + 4 + functionSz + 1 + sourceSz + 1 + nameSz ); + const auto sz32 = uint32_t( 2 + 4 + 4 + functionSz + 1 + sourceSz + 1 + nameSz ); + assert( sz32 <= std::numeric_limits::max() ); + const auto sz = uint16_t( sz32 ); auto ptr = (char*)tracy_malloc( sz ); - memcpy( ptr, &sz, 4 ); - memset( ptr + 4, 0, 4 ); - memcpy( ptr + 8, &line, 4 ); - memcpy( ptr + 12, function, functionSz ); - ptr[12 + functionSz] = '\0'; - memcpy( ptr + 12 + functionSz + 1, source, sourceSz ); - ptr[12 + functionSz + 1 + sourceSz] = '\0'; + memcpy( ptr, &sz, 2 ); + memset( ptr + 2, 0, 4 ); + memcpy( ptr + 6, &line, 4 ); + memcpy( ptr + 10, function, functionSz ); + ptr[10 + functionSz] = '\0'; + memcpy( ptr + 10 + functionSz + 1, source, sourceSz ); + ptr[10 + functionSz + 1 + sourceSz] = '\0'; if( nameSz != 0 ) { - memcpy( ptr + 12 + functionSz + 1 + sourceSz + 1, name, nameSz ); + memcpy( ptr + 10 + functionSz + 1 + sourceSz + 1, name, nameSz ); } return uint64_t( ptr ); }