From d04fd4602d102fedd334f1e7fcd1b6f5f99c7fe8 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Mon, 20 Nov 2023 22:22:23 +0000 Subject: [PATCH] Codechange: Assert that max width passed to GetStringHeight is non-zero. Max width of zero will cause text layouters to crash, potentially after exhausting memory first. --- src/gfx.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/gfx.cpp b/src/gfx.cpp index 5029446db4..c6dcfce611 100644 --- a/src/gfx.cpp +++ b/src/gfx.cpp @@ -693,6 +693,7 @@ int DrawString(int left, int right, int top, StringID str, TextColour colour, St */ int GetStringHeight(std::string_view str, int maxw, FontSize fontsize) { + assert(maxw > 0); Layouter layout(str, maxw, TC_FROMSTRING, fontsize); return layout.GetBounds().height; }