From e70fef06509d540ba6fd1ad4a307f35e9850abef Mon Sep 17 00:00:00 2001 From: Pieter-Jan Briers Date: Thu, 28 May 2026 07:49:54 +0200 Subject: [PATCH] SafeStringCopy log fix (#1858) * Fix logging on SafeStringCopy overflow failure * Fix CRASH() macro to not take varargs Didn't work, probably a remnant of a different iteration I made. * Fix ValidateChannel CRASH call --------- Co-authored-by: Luke Street --- include/global.h | 2 +- src/dusk/audio/DuskDsp.cpp | 7 +++---- src/dusk/string.cpp | 4 ++-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/include/global.h b/include/global.h index 170461ea5f..2a8e182bfa 100644 --- a/include/global.h +++ b/include/global.h @@ -225,7 +225,7 @@ using std::isnan; #define IS_REF_NONNULL(r) (1) #endif -#define CRASH(msg, ...) OSPanic(__FILE__, __LINE__, "%s", msg, ##__VA_ARGS__) +#define CRASH(msg) OSPanic(__FILE__, __LINE__, "%s", msg) // Some basic macros that are more convenient than putting down #if blocks for one-line changes. #if TARGET_PC diff --git a/src/dusk/audio/DuskDsp.cpp b/src/dusk/audio/DuskDsp.cpp index 697371702f..ca4d079e92 100644 --- a/src/dusk/audio/DuskDsp.cpp +++ b/src/dusk/audio/DuskDsp.cpp @@ -85,10 +85,9 @@ static bool ValidateChannelWaveFormat(const JASDsp::TChannel& channel) { */ static void ValidateChannel(const JASDsp::TChannel& channel) { if (!ValidateChannelWaveFormat(channel)) { - CRASH( - "Unable to handle channel format: %02x, %02x\n", - channel.mSamplesPerBlock, - channel.mBytesPerBlock); + const auto msg = fmt::format("Unable to handle channel format: {:02x}, {:02x}\n", + channel.mSamplesPerBlock, channel.mBytesPerBlock); + CRASH(msg.c_str()); } } diff --git a/src/dusk/string.cpp b/src/dusk/string.cpp index e40094ef70..7666f9d9ae 100644 --- a/src/dusk/string.cpp +++ b/src/dusk/string.cpp @@ -45,10 +45,10 @@ void SafeStringCopy(char* buffer, size_t bufSize, const char* src) { const auto srcSize = strlen(src); if (srcSize > bufSize - 1) [[unlikely]] { const auto msg = fmt::format( - "Destination buffer too small! Need %d, have %d", + "Destination buffer too small! Need {}, have {}", srcSize + 1, bufSize); - CRASH("%s", msg.c_str()); + CRASH(msg.c_str()); } strncpyProxy(buffer, src, bufSize);