From c2b33e3541c32a86df7196a84acdf76f626f00fe Mon Sep 17 00:00:00 2001 From: frutiemax Date: Sat, 1 Jan 2022 08:10:42 -0500 Subject: [PATCH] Close #16002: Segfault opening ride statistics for huge ride --- src/openrct2/localisation/Formatter.h | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/openrct2/localisation/Formatter.h b/src/openrct2/localisation/Formatter.h index fb392c9d97..1ca54da237 100644 --- a/src/openrct2/localisation/Formatter.h +++ b/src/openrct2/localisation/Formatter.h @@ -10,17 +10,17 @@ #pragma once #include "../common.h" +#include "../core/Guard.hpp" #include #include extern thread_local uint8_t gCommonFormatArgs[80]; - enum class ride_id_t : uint16_t; class Formatter { - std::array Buffer{}; + std::array Buffer{}; uint8_t* StartBuf{}; uint8_t* CurrentBuf{}; @@ -59,7 +59,12 @@ public: void Increment(size_t count) { - CurrentBuf += count; + auto finalCount = NumBytes() + count; + Guard::Assert(finalCount < Buffer.size(), "Increment is greater than buffer size!"); + if (finalCount < Buffer.size()) + { + CurrentBuf += count; + } } void Rewind()