Fix: decisions being made on uninitialised memory in the SDL video driver #9027
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation / Problem
Valgrind:
==27199== Conditional jump or move depends on uninitialised value(s)
==27199== at 0x858DBD: VideoDriver::Tick() (video_driver.cpp:150)
==27199== by 0x85605C: VideoDriver_SDL_Base::LoopOnce() (sdl2_v.cpp:642)
==27199== by 0x85609C: VideoDriver_SDL_Base::MainLoop() (sdl2_v.cpp:660)
==27199== by 0xA44F07: openttd_main(int, char**) (openttd.cpp:837)
==27199== by 0x7A7BB7: main (unix.cpp:262)
==27199==
==27199== Conditional jump or move depends on uninitialised value(s)
==27199== at 0x85632F: VideoDriver_SDL_Base::LockVideoBuffer() (sdl2_v.cpp:721)
==27199== by 0x858E17: VideoDriver::Tick() (video_driver.cpp:160)
==27199== by 0x85605C: VideoDriver_SDL_Base::LoopOnce() (sdl2_v.cpp:642)
==27199== by 0x85609C: VideoDriver_SDL_Base::MainLoop() (sdl2_v.cpp:660)
==27199== by 0xA44F07: openttd_main(int, char**) (openttd.cpp:837)
==27199== by 0x7A7BB7: main (unix.cpp:262)
Description
The issue in VideoDriver::Tick might trigger fast forward if unlucky, since the fast forward booleans could be non-false due to the uninitialised memory. Especially fast_forward_key_pressed is tricky as that only gets set for _DEBUG builds.
The VideoDriver_SDL_Base::LockVideoBuffer might cause locking not to happen when it should, if initialised incorrectly.
Limitations
None
Checklist for review
Some things are not automated, and forgotten often. This list is a reminder for the reviewers.