GOB: Fix invalid reads in Geisha's minigames

This commit is contained in:
Sven Hesse 2012-06-03 18:58:03 +02:00
parent d124b87649
commit db99d23717
4 changed files with 32 additions and 22 deletions

View file

@ -167,19 +167,21 @@ bool ANIObject::isIn(const ANIObject &obj) const {
obj.isIn(frameX + frameWidth - 1, frameY + frameHeight - 1);
}
void ANIObject::draw(Surface &dest, int16 &left, int16 &top,
bool ANIObject::draw(Surface &dest, int16 &left, int16 &top,
int16 &right, int16 &bottom) {
if (!_visible)
return;
return false;
if (_cmp)
drawCMP(dest, left, top, right, bottom);
return drawCMP(dest, left, top, right, bottom);
else if (_ani)
drawANI(dest, left, top, right, bottom);
return drawANI(dest, left, top, right, bottom);
return false;
}
void ANIObject::drawCMP(Surface &dest, int16 &left, int16 &top,
bool ANIObject::drawCMP(Surface &dest, int16 &left, int16 &top,
int16 &right, int16 &bottom) {
if (!_background) {
@ -209,9 +211,11 @@ void ANIObject::drawCMP(Surface &dest, int16 &left, int16 &top,
top = _backgroundTop;
right = _backgroundRight;
bottom = _backgroundBottom;
return true;
}
void ANIObject::drawANI(Surface &dest, int16 &left, int16 &top,
bool ANIObject::drawANI(Surface &dest, int16 &left, int16 &top,
int16 &right, int16 &bottom) {
if (!_background) {
@ -224,7 +228,7 @@ void ANIObject::drawANI(Surface &dest, int16 &left, int16 &top,
const ANIFile::Animation &animation = _ani->getAnimationInfo(_animation);
if (_frame >= animation.frameCount)
return;
return false;
const ANIFile::FrameArea &area = animation.frameAreas[_frame];
@ -244,13 +248,15 @@ void ANIObject::drawANI(Surface &dest, int16 &left, int16 &top,
top = _backgroundTop;
right = _backgroundRight;
bottom = _backgroundBottom;
return true;
}
void ANIObject::clear(Surface &dest, int16 &left, int16 &top,
bool ANIObject::clear(Surface &dest, int16 &left, int16 &top,
int16 &right, int16 &bottom) {
if (!_drawn)
return;
return false;
const int16 bgRight = _backgroundRight - _backgroundLeft;
const int16 bgBottom = _backgroundBottom - _backgroundTop;
@ -263,6 +269,8 @@ void ANIObject::clear(Surface &dest, int16 &left, int16 &top,
top = _backgroundTop;
right = _backgroundRight;
bottom = _backgroundBottom;
return true;
}
void ANIObject::advance() {

View file

@ -93,9 +93,9 @@ public:
bool lastFrame() const;
/** Draw the current frame onto the surface and return the affected rectangle. */
void draw(Surface &dest, int16 &left, int16 &top, int16 &right, int16 &bottom);
bool draw(Surface &dest, int16 &left, int16 &top, int16 &right, int16 &bottom);
/** Draw the current frame from the surface and return the affected rectangle. */
void clear(Surface &dest, int16 &left , int16 &top, int16 &right, int16 &bottom);
bool clear(Surface &dest, int16 &left , int16 &top, int16 &right, int16 &bottom);
/** Advance the animation to the next frame. */
virtual void advance();
@ -123,8 +123,8 @@ private:
int16 _backgroundRight; ///< The right position of the saved background.
int16 _backgroundBottom; ///< The bottom position of the saved background.
void drawCMP(Surface &dest, int16 &left, int16 &top, int16 &right, int16 &bottom);
void drawANI(Surface &dest, int16 &left, int16 &top, int16 &right, int16 &bottom);
bool drawCMP(Surface &dest, int16 &left, int16 &top, int16 &right, int16 &bottom);
bool drawANI(Surface &dest, int16 &left, int16 &top, int16 &right, int16 &bottom);
};
} // End of namespace Gob

View file

@ -706,16 +706,16 @@ void Diving::updateAnims() {
for (Common::List<ANIObject *>::iterator a = _anims.reverse_begin();
a != _anims.end(); --a) {
(*a)->clear(*_vm->_draw->_backSurface, left, top, right, bottom);
_vm->_draw->dirtiedRect(_vm->_draw->_backSurface, left, top, right, bottom);
if ((*a)->clear(*_vm->_draw->_backSurface, left, top, right, bottom))
_vm->_draw->dirtiedRect(_vm->_draw->_backSurface, left, top, right, bottom);
}
// Draw the current animation frames
for (Common::List<ANIObject *>::iterator a = _anims.begin();
a != _anims.end(); ++a) {
(*a)->draw(*_vm->_draw->_backSurface, left, top, right, bottom);
_vm->_draw->dirtiedRect(_vm->_draw->_backSurface, left, top, right, bottom);
if ((*a)->draw(*_vm->_draw->_backSurface, left, top, right, bottom))
_vm->_draw->dirtiedRect(_vm->_draw->_backSurface, left, top, right, bottom);
(*a)->advance();
}

View file

@ -298,6 +298,8 @@ void Penetration::deinit() {
_objects = 0;
_sprites = 0;
_sub = 0;
}
void Penetration::createMap() {
@ -503,14 +505,14 @@ void Penetration::checkShields() {
}
void Penetration::updateAnims() {
int16 left, top, right, bottom;
int16 left = 0, top = 0, right = 0, bottom = 0;
// Clear the previous animation frames
for (Common::List<ANIObject *>::iterator a = _anims.reverse_begin();
a != _anims.end(); --a) {
(*a)->clear(*_vm->_draw->_backSurface, left, top, right, bottom);
_vm->_draw->dirtiedRect(_vm->_draw->_backSurface, left, top, right, bottom);
if ((*a)->clear(*_vm->_draw->_backSurface, left, top, right, bottom))
_vm->_draw->dirtiedRect(_vm->_draw->_backSurface, left, top, right, bottom);
}
if (_mapUpdate) {
@ -526,8 +528,8 @@ void Penetration::updateAnims() {
for (Common::List<ANIObject *>::iterator a = _anims.begin();
a != _anims.end(); ++a) {
(*a)->draw(*_vm->_draw->_backSurface, left, top, right, bottom);
_vm->_draw->dirtiedRect(_vm->_draw->_backSurface, left, top, right, bottom);
if ((*a)->draw(*_vm->_draw->_backSurface, left, top, right, bottom))
_vm->_draw->dirtiedRect(_vm->_draw->_backSurface, left, top, right, bottom);
(*a)->advance();
}