Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: decisions being made on uninitialised memory in the SDL video driver #9027

Merged
merged 3 commits into from Apr 12, 2021

Conversation

rubidium42
Copy link
Contributor

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.

  • The bug fix is important enough to be backported? (label: 'backport requested')
  • This PR affects the save game format? (label 'savegame upgrade')
  • This PR affects the GS/AI API? (label 'needs review: Script API')
    • ai_changelog.hpp, gs_changelog.hpp need updating.
    • The compatibility wrappers (compat_*.nut) need updating.
  • This PR affects the NewGRF API? (label 'needs review: NewGRF')

@TrueBrain
Copy link
Member

I think this change should be two commits.

One fixes something in SDL, the other fixes something for all video drivers.

Also, your commit message is as vague as one can be ;) Maybe a bit more to the point helps a lot in understanding what your change is about to do, instead of having to read that in the code :D

Fix: SDL buffer is not initialized as locked
Fix: fast-forward can be enabled on startup due to not being initialized

or something? :)

TrueBrain
TrueBrain previously approved these changes Apr 12, 2021
Copy link
Member

@TrueBrain TrueBrain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did smoketest on win32, unsurprisingly, no issues. But as I cannot reproduce #8967 no way of telling it fixes that. But it is rather likely.

@TrueBrain TrueBrain merged commit 468b1c6 into OpenTTD:master Apr 12, 2021
@rubidium42 rubidium42 deleted the video_uninitialised_memory branch April 12, 2021 19:17
@TrueBrain TrueBrain added the backport requested This PR should be backport to current release (RC / stable) label Apr 13, 2021
@LordAro LordAro added backported This PR is backported to a current release (RC / stable) and removed backport requested This PR should be backport to current release (RC / stable) labels Apr 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backported This PR is backported to a current release (RC / stable)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants