From 531029f54aa5381a72d5f08a2e31721932dcfaa0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torbj=C3=B6rn=20Andersson?= Date: Thu, 5 Feb 2015 00:04:04 +0100 Subject: [PATCH] HUGO: Avoid drawing text above screen (bug #6799) When drawing cursor text, don't draw it above the top of the screen, since this would lead to memory corruption and crashes. I'm not quite sure this is all of bug #6799 since it also mentioned that "sometimes simply using a hotspot will be enough", but it's a start. --- engines/hugo/mouse.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/engines/hugo/mouse.cpp b/engines/hugo/mouse.cpp index 558a596b358..3674c907577 100644 --- a/engines/hugo/mouse.cpp +++ b/engines/hugo/mouse.cpp @@ -121,12 +121,24 @@ void MouseHandler::cursorText(const char *buffer, const int16 cx, const int16 cy int16 sx, sy; if (cx < kXPix / 2) { sx = cx + kCursorNameOffX; - sy = (_vm->_inventory->getInventoryObjId() == -1) ? cy + kCursorNameOffY : cy + kCursorNameOffY - (_vm->_screen->fontHeight() + 1); + if (_vm->_inventory->getInventoryObjId() == -1) { + sy = cy + kCursorNameOffY; + } else { + sy = cy + kCursorNameOffY - (_vm->_screen->fontHeight() + 1); + if (sy < 0) { + sx = cx + kCursorNameOffX + 25; + sy = cy + kCursorNameOffY; + } + } } else { sx = cx - sdx - kCursorNameOffX / 2; sy = cy + kCursorNameOffY; } + if (sy < 0) { + sy = 0; + } + // Display the string and add rect to display list _vm->_screen->shadowStr(sx, sy, buffer, _TBRIGHTWHITE); _vm->_screen->displayList(kDisplayAdd, sx, sy, sdx, sdy);