diff options
author | Filippos Karapetis | 2009-12-30 18:33:03 +0000 |
---|---|---|
committer | Filippos Karapetis | 2009-12-30 18:33:03 +0000 |
commit | d4556f5a26864171e4ff437aae855f8f79e9531a (patch) | |
tree | 735d5616ef2943082f8526425e319a96c705c219 /engines/sci/engine | |
parent | 1e4a7752411317919f7420009abc59595774b1ab (diff) | |
download | scummvm-rg350-d4556f5a26864171e4ff437aae855f8f79e9531a.tar.gz scummvm-rg350-d4556f5a26864171e4ff437aae855f8f79e9531a.tar.bz2 scummvm-rg350-d4556f5a26864171e4ff437aae855f8f79e9531a.zip |
SCI32: Added sanity checks to kAddScreenItem and kUpdateScreenItem, so that they don't try and draw cels outside the screen
svn-id: r46767
Diffstat (limited to 'engines/sci/engine')
-rw-r--r-- | engines/sci/engine/kernel32.cpp | 42 |
1 files changed, 34 insertions, 8 deletions
diff --git a/engines/sci/engine/kernel32.cpp b/engines/sci/engine/kernel32.cpp index d6fe995467..d984bf4117 100644 --- a/engines/sci/engine/kernel32.cpp +++ b/engines/sci/engine/kernel32.cpp @@ -640,13 +640,26 @@ reg_t kSave(EngineState *s, int argc, reg_t *argv) { reg_t kAddScreenItem(EngineState *s, int argc, reg_t *argv) { reg_t viewObj = argv[0]; uint16 viewId = GET_SEL32V(s->_segMan, viewObj, view); - int16 loopNo = GET_SEL32V(s->_segMan, viewObj, loop); - int16 celNo = GET_SEL32V(s->_segMan, viewObj, cel); - int16 leftPos = GET_SEL32V(s->_segMan, viewObj, x); - int16 topPos = GET_SEL32V(s->_segMan, viewObj, y); + uint16 loopNo = GET_SEL32V(s->_segMan, viewObj, loop); + uint16 celNo = GET_SEL32V(s->_segMan, viewObj, cel); + uint16 leftPos = GET_SEL32V(s->_segMan, viewObj, x); + uint16 topPos = GET_SEL32V(s->_segMan, viewObj, y); int16 priority = GET_SEL32V(s->_segMan, viewObj, priority); //int16 control = 0; + // Theoretically, leftPos and topPos should be sane + // Apparently, sometimes they're not, therefore I'm adding some sanity checks here so that + // the hack underneath does not try and draw cels outside the screen coordinates + if (leftPos >= (int16)s->_gui->getScreenWidth()) { + warning("kAddScreenItem: invalid left position (%d), resetting to 0", leftPos); + leftPos = 0; + } + + if (topPos >= s->_gui->getScreenHeight()) { + warning("kAddScreenItem: invalid top position (%d), resetting to 0", topPos); + topPos = 0; + } + // HACK: just draw the view on screen if (viewId != 0xffff) s->_gui->drawCel(viewId, loopNo, celNo, leftPos, topPos, priority, 0); @@ -661,13 +674,26 @@ reg_t kAddScreenItem(EngineState *s, int argc, reg_t *argv) { reg_t kUpdateScreenItem(EngineState *s, int argc, reg_t *argv) { reg_t viewObj = argv[0]; uint16 viewId = GET_SEL32V(s->_segMan, viewObj, view); - int16 loopNo = GET_SEL32V(s->_segMan, viewObj, loop); - int16 celNo = GET_SEL32V(s->_segMan, viewObj, cel); - int16 leftPos = GET_SEL32V(s->_segMan, viewObj, x); - int16 topPos = GET_SEL32V(s->_segMan, viewObj, y); + uint16 loopNo = GET_SEL32V(s->_segMan, viewObj, loop); + uint16 celNo = GET_SEL32V(s->_segMan, viewObj, cel); + uint16 leftPos = GET_SEL32V(s->_segMan, viewObj, x); + uint16 topPos = GET_SEL32V(s->_segMan, viewObj, y); int16 priority = GET_SEL32V(s->_segMan, viewObj, priority); //int16 control = 0; + // Theoretically, leftPos and topPos should be sane + // Apparently, sometimes they're not, therefore I'm adding some sanity checks here so that + // the hack underneath does not try and draw cels outside the screen coordinates + if (leftPos >= s->_gui->getScreenWidth()) { + warning("kUpdateScreenItem: invalid left position (%d), resetting to 0", leftPos); + leftPos = 0; + } + + if (topPos >= s->_gui->getScreenHeight()) { + warning("kUpdateScreenItem: invalid top position (%d), resetting to 0", topPos); + topPos = 0; + } + // HACK: just draw the view on screen if (viewId != 0xffff) s->_gui->drawCel(viewId, loopNo, celNo, leftPos, topPos, priority, 0); |