From c00cc90b1f3ffdbcb46cc6fee60bda659bd27a2e Mon Sep 17 00:00:00 2001 From: Johan Mattsson <39247600+mjunix@users.noreply.github.com> Date: Thu, 3 Feb 2022 21:42:12 +0100 Subject: [PATCH] Fix bounds checks and a nullptr check --- src/openrct2-ui/windows/Scenery.cpp | 2 +- src/openrct2/interface/Window.cpp | 2 +- src/openrct2/localisation/LanguagePack.cpp | 4 ++-- src/openrct2/ride/Ride.cpp | 3 ++- src/openrct2/title/TitleSequence.cpp | 2 +- 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/openrct2-ui/windows/Scenery.cpp b/src/openrct2-ui/windows/Scenery.cpp index 811005a6a6..0809b9e9f9 100644 --- a/src/openrct2-ui/windows/Scenery.cpp +++ b/src/openrct2-ui/windows/Scenery.cpp @@ -1330,7 +1330,7 @@ void WindowSceneryScrollpaint(rct_window* w, rct_drawpixelinfo* dpi, int32_t scr auto numColumns = WindowSceneryGetNumColumns(w); auto tabIndex = gWindowSceneryActiveTabIndex; - if (tabIndex > _tabEntries.size()) + if (tabIndex >= _tabEntries.size()) { return; } diff --git a/src/openrct2/interface/Window.cpp b/src/openrct2/interface/Window.cpp index a14800ed2b..061d7eb460 100644 --- a/src/openrct2/interface/Window.cpp +++ b/src/openrct2/interface/Window.cpp @@ -1082,7 +1082,7 @@ void window_zoom_out(rct_window* w, bool atCursor) void main_window_zoom(bool zoomIn, bool atCursor) { auto* mainWindow = window_get_main(); - if (mainWindow != nullptr) + if (mainWindow == nullptr) return; if (gScreenFlags & SCREEN_FLAGS_TITLE_DEMO) diff --git a/src/openrct2/localisation/LanguagePack.cpp b/src/openrct2/localisation/LanguagePack.cpp index 65a7f220e8..539871f761 100644 --- a/src/openrct2/localisation/LanguagePack.cpp +++ b/src/openrct2/localisation/LanguagePack.cpp @@ -131,7 +131,7 @@ public: void RemoveString(rct_string_id stringId) override { - if (_strings.size() >= static_cast(stringId)) + if (_strings.size() > static_cast(stringId)) { _strings[stringId] = std::string(); } @@ -139,7 +139,7 @@ public: void SetString(rct_string_id stringId, const std::string& str) override { - if (_strings.size() >= static_cast(stringId)) + if (_strings.size() > static_cast(stringId)) { _strings[stringId] = str; } diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index f4c5333374..d090dfa80b 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -678,10 +678,11 @@ bool track_block_get_previous(const CoordsXYE& trackPos, track_begin_end* outTra return false; auto trackElement = trackPos.element->AsTrack(); - const auto& ted = GetTrackElementDescriptor(trackElement->GetTrackType()); if (trackElement == nullptr) return false; + const auto& ted = GetTrackElementDescriptor(trackElement->GetTrackType()); + auto rideIndex = trackElement->GetRideIndex(); auto ride = get_ride(rideIndex); if (ride == nullptr) diff --git a/src/openrct2/title/TitleSequence.cpp b/src/openrct2/title/TitleSequence.cpp index e85dab8923..a5f9df4b97 100644 --- a/src/openrct2/title/TitleSequence.cpp +++ b/src/openrct2/title/TitleSequence.cpp @@ -98,7 +98,7 @@ std::unique_ptr LoadTitleSequence(const std::string& path) std::unique_ptr TitleSequenceGetParkHandle(const TitleSequence& seq, size_t index) { std::unique_ptr handle; - if (index <= seq.Saves.size()) + if (index < seq.Saves.size()) { const auto& filename = seq.Saves[index]; if (seq.IsZip)