From 9e303b063f4923c4cbc8a75ca15aff76c3a69303 Mon Sep 17 00:00:00 2001 From: Luke Street Date: Tue, 10 Mar 2026 21:02:16 -0600 Subject: [PATCH] Fix UB in dRes_control_c::newResInfo --- src/d/d_resorce.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/d/d_resorce.cpp b/src/d/d_resorce.cpp index 9bcbd1c3a1..94adaeb053 100644 --- a/src/d/d_resorce.cpp +++ b/src/d/d_resorce.cpp @@ -867,6 +867,13 @@ dRes_info_c* dRes_control_c::getResInfo(char const* i_arcName, dRes_info_c* i_re dRes_info_c* dRes_control_c::newResInfo(dRes_info_c* i_resInfo, int i_infoNum) { for (int i = 0; i < i_infoNum; i++) { if (i_resInfo->getCount() == 0) { +#if TARGET_PC + // The original code reuses explicitly-destructed dRes_info_c slots without + // placement-new. The destructor's cleanup writes (mArchive = NULL, etc.) are + // dead stores from the compiler's perspective and may be optimized away, + // leaving stale pointers. Reconstruct the slot to ensure a clean state. + new (i_resInfo) dRes_info_c(); +#endif return i_resInfo; } i_resInfo++;