From c136232c97779cd35e9dee00622583bbb0924aad Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Fri, 31 Jul 2026 23:15:57 +0200 Subject: [PATCH] Use strzcpy in client library. --- public/client/TracyCallstack.cpp | 4 ++-- public/client/windows/TracyETW.cpp | 14 +++++--------- public/tracy/TracyCUDA.hpp | 3 ++- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/public/client/TracyCallstack.cpp b/public/client/TracyCallstack.cpp index 59c4182f..9d0b3507 100644 --- a/public/client/TracyCallstack.cpp +++ b/public/client/TracyCallstack.cpp @@ -8,6 +8,7 @@ #include "TracyFastVector.hpp" #include "TracyStringHelpers.hpp" #include "../common/TracyAlloc.hpp" +#include "../common/TracyString.hpp" #include "../common/TracySystem.hpp" @@ -1461,8 +1462,7 @@ static const char* DecodeCallstackPtrFastExternal( uint64_t ptr ) } if( symname ) { - strncpy( ret, symname, sizeof( ret ) - 1 ); - ret[sizeof( ret ) - 1] = '\0'; + strzcpy( ret, symname, sizeof( ret ) ); } else { diff --git a/public/client/windows/TracyETW.cpp b/public/client/windows/TracyETW.cpp index 3d592af8..4ddc9292 100644 --- a/public/client/windows/TracyETW.cpp +++ b/public/client/windows/TracyETW.cpp @@ -6,6 +6,8 @@ #include #include +#include "../../common/TracyString.hpp" + namespace tracy { namespace etw @@ -330,9 +332,7 @@ static Session StartSingletonKernelLoggerSession( ULONGLONG EnableFlags ) { Session session = {}; - size_t maxlen = sizeof( session.name ) - 1; - strncpy( session.name, KERNEL_LOGGER_NAMEA, maxlen ); - session.name[maxlen] = '\0'; + strzcpy( session.name, KERNEL_LOGGER_NAMEA, sizeof( session.name ) ); auto& props = session.properties; props.LoggerNameOffset = offsetof( Session, name ); @@ -364,9 +364,7 @@ static Session StartPrivateKernelSession( const CHAR* name ) { Session session = {}; - size_t maxlen = sizeof( session.name ) - 1; - strncpy( session.name, name, maxlen ); - session.name[maxlen] = '\0'; + strzcpy( session.name, name, sizeof( session.name ) ); auto& props = session.properties; props.LoggerNameOffset = offsetof( Session, name ); @@ -398,9 +396,7 @@ static Session StartUserSession( const CHAR* name ) { Session session = {}; - size_t maxlen = sizeof( session.name ) - 1; - strncpy( session.name, name, maxlen ); - session.name[maxlen] = '\0'; + strzcpy( session.name, name, sizeof( session.name ) ); auto& props = session.properties; props.LoggerNameOffset = offsetof( Session, name ); diff --git a/public/tracy/TracyCUDA.hpp b/public/tracy/TracyCUDA.hpp index c5134807..a859ed1b 100644 --- a/public/tracy/TracyCUDA.hpp +++ b/public/tracy/TracyCUDA.hpp @@ -26,6 +26,7 @@ using CUDACtx = std::nullptr_t; #include #include #include +#include #include #include #include @@ -405,7 +406,7 @@ struct StringTable { if (!table.fetch(str, memoized)) { ZoneNamedN(lookup, "StringTable::insert", instrument); char* copy = (char*)tracyMalloc(str.size() + 1); - strncpy(copy, str.data(), str.size()); + memcpy(copy, str.data(), str.size()); copy[str.size()] = '\0'; std::string_view value (copy, str.size()); auto [it, inserted] = table.emplace(value, value);