From c95c1ab25006147ede1ea8aa3b24a50f0c17ba3b Mon Sep 17 00:00:00 2001 From: Misa Date: Sun, 28 Jun 2020 10:40:58 -0700 Subject: [PATCH] Add bounds check to textbox functions that use `m` It seems to be a bit bad to blindly use `m` without checking it. In fact, this has caused a few segfaults already, actually. --- desktop_version/src/Graphics.cpp | 45 ++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/desktop_version/src/Graphics.cpp b/desktop_version/src/Graphics.cpp index d21bd4bc..36f5091a 100644 --- a/desktop_version/src/Graphics.cpp +++ b/desktop_version/src/Graphics.cpp @@ -1141,16 +1141,31 @@ void Graphics::textboxremove() void Graphics::textboxtimer( int t ) { + if (!INBOUNDS(m, textbox)) + { + return; + } + textbox[m].timer=t; } void Graphics::addline( std::string t ) { + if (!INBOUNDS(m, textbox)) + { + return; + } + textbox[m].addline(t); } void Graphics::textboxadjust() { + if (!INBOUNDS(m, textbox)) + { + return; + } + textbox[m].adjust(); } @@ -2787,33 +2802,63 @@ void Graphics::setwarprect( int a, int b, int c, int d ) void Graphics::textboxcenter() { + if (!INBOUNDS(m, textbox)) + { + return; + } + textbox[m].centerx(); textbox[m].centery(); } void Graphics::textboxcenterx() { + if (!INBOUNDS(m, textbox)) + { + return; + } + textbox[m].centerx(); } int Graphics::textboxwidth() { + if (!INBOUNDS(m, textbox)) + { + return 0; + } + return textbox[m].w; } void Graphics::textboxmove(int xo, int yo) { + if (!INBOUNDS(m, textbox)) + { + return; + } + textbox[m].xp += xo; textbox[m].yp += yo; } void Graphics::textboxmoveto(int xo) { + if (!INBOUNDS(m, textbox)) + { + return; + } + textbox[m].xp = xo; } void Graphics::textboxcentery() { + if (!INBOUNDS(m, textbox)) + { + return; + } + textbox[m].centery(); }