From 6764a6036450c252bcf5afeca392fa698c402d76 Mon Sep 17 00:00:00 2001 From: Max Roncace Date: Thu, 26 Mar 2026 20:11:39 -0400 Subject: [PATCH] Fix UB in search_ground_1 in d_a_e_yg This could cause a crash and was previously fixed by 7d3795f7, but it's a band-aid solution. This fix addresses the underlying bug that actually causes the crash. The workaround remains in place for now because similar bugs related to NaNs have been encountered, and it's not currently known how many places in the codebase are affected as well. --- src/d/actor/d_a_e_yg.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/d/actor/d_a_e_yg.cpp b/src/d/actor/d_a_e_yg.cpp index 43f91ee793..9ab6c80e6d 100644 --- a/src/d/actor/d_a_e_yg.cpp +++ b/src/d/actor/d_a_e_yg.cpp @@ -527,7 +527,7 @@ static void search_ground_1(e_yg_class* i_this) { fopAc_ac_c* actor = (fopAc_ac_c*)&i_this->actor; dBgS_LinChk lin_chk; cXyz start, end, work; - cXyz pos[16]; + cXyz pos[16]{}; s16 y_rot = actor->shape_angle.y; s8 line_cross_flag = false; @@ -560,6 +560,14 @@ static void search_ground_1(e_yg_class* i_this) { pos[i] = actor->current.pos; pos[i].x += 10000.0f; } + } else { + // Ensure all elements are initialized. This function is buggy and + // blows up if pos[0].x or pos[0].z is NaN, but for some reason this + // never happens on hardware - probably just dumb luck. +#if AVOID_UB + pos[i] = actor->current.pos; + pos[i].x += 10000.0f; +#endif } ANGLE_ADD(y_rot, 0x1000);