From 0d4afee94772d1824bba34a0b70b86f8257bf26a Mon Sep 17 00:00:00 2001 From: fallenoak Date: Sun, 7 Dec 2025 13:32:53 -0600 Subject: [PATCH] fix(sound): correct potential use-after-scope in SI2::PlaySoundKit --- src/sound/SI2.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/sound/SI2.cpp b/src/sound/SI2.cpp index b54ebaf..5dcc5a9 100644 --- a/src/sound/SI2.cpp +++ b/src/sound/SI2.cpp @@ -369,6 +369,13 @@ int32_t SI2::PlaySoundKit(int32_t id, int32_t a2, SOUNDKITOBJECT* object, SoundK return 15; } + // Get sound pointer + + // Stack-allocated SESound is used as placeholder if no sound was provided by object. This + // needs to be declared here, at function scope, to avoid potential use-after-scope behavior + // in CompleteLoad() and Play() below. + SESound newSound = {}; + SESound* sound; if (object) { @@ -376,7 +383,6 @@ int32_t SI2::PlaySoundKit(int32_t id, int32_t a2, SOUNDKITOBJECT* object, SoundK // TODO } else { - SESound newSound = {}; sound = &newSound; // TODO