From e729556f305c7bd6e71d94cd15868a0272de2ef4 Mon Sep 17 00:00:00 2001 From: Miro Kropacek Date: Tue, 19 May 2026 21:46:26 +1000 Subject: [PATCH] AUDIO: Don't use static Common::String instance This fixes the ASAN issue. --- audio/rate.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/audio/rate.cpp b/audio/rate.cpp index aa50346b0df..4638f827270 100644 --- a/audio/rate.cpp +++ b/audio/rate.cpp @@ -84,18 +84,20 @@ private: int simpleConvert(AudioStream &input, st_sample_t *outBuffer, st_size_t numSamples, st_volume_t vol_l, st_volume_t vol_r); int interpolateConvert(AudioStream &input, st_sample_t *outBuffer, st_size_t numSamples, st_volume_t vol_l, st_volume_t vol_r); - // keep a single printConvertType shared across all RateConverter_Impl specializations + // keep a single printConvertType shared across all RateConverter_Impl specializations. + // PrintContext must be trivially destructible: it lives in a function-scope static and + // is torn down after the OSystem (and its memory pool that backs Common::String) is gone. struct PrintContext { st_rate_t previousInRate = 0; - Common::String previousGameId; + char previousGameId[64] = { 0 }; }; void printConvertType(const char *name, PrintContext &ctx) const { - const Common::String activeDomain = ConfMan.getActiveDomainName(); + const Common::String &activeDomain = ConfMan.getActiveDomainName(); if (!activeDomain.empty() && (ctx.previousInRate != _inRate || - ctx.previousGameId != activeDomain)) { + strncmp(ctx.previousGameId, activeDomain.c_str(), sizeof(ctx.previousGameId)) != 0)) { ctx.previousInRate = _inRate; - ctx.previousGameId = activeDomain; + Common::strlcpy(ctx.previousGameId, activeDomain.c_str(), sizeof(ctx.previousGameId)); debugC(kDebugLevelGAudio, "RateConverter_Impl::%s[%s]: inRate %d Hz (%s) => outRate %d Hz (%s)", name, activeDomain.c_str(), _inRate, inStereo ? "stereo" : "mono", _outRate, outStereo ? "stereo" : "mono");