mupen64plus / mupen64plus-core

Core module of the Mupen64Plus project
1.32k stars 258 forks source link

Initialize dd_rom_size to 0 if load_dd_disk fails to fix possible runtime errors during initialization #958

Closed DarioSamo closed 2 years ago

DarioSamo commented 2 years ago

As described in my comment on PR #920.

This PR seems to have introduced a runtime error where dd_rom_size can now be uninitialized in the main_run function because load_dd_rom has been moved inside the branch and executed only if load_dd_disk succeeds. It seems init_device relies on dd_rom_size being correctly initialized later, so this seems to introduce a random chance of incorrect behavior based on whether dd_rom_size happens to be 0 or not. I haven't actually ran into the error myself, but MSVC's debugger caught this pretty quickly on the Debug configuration and would not allow me to run further until it was fixed. The obvious solution to me seems to just handle the else case on the branch mentioned above, but I figured I'd report it first to the original submitter before making a PR myself.

If you'd prefer the default initialization to be handled differently rather than explicitly on the else branch, let me know.