diff --git a/engines/grim/costume.cpp b/engines/grim/costume.cpp index db0abef554b..200582c49e1 100644 --- a/engines/grim/costume.cpp +++ b/engines/grim/costume.cpp @@ -407,10 +407,18 @@ Model *Costume::getModel() { } void Costume::setChoreLastFrame(int num) { + if (num < 0 || num >= _numChores) { + Debug::warning(Debug::Chores, "Requested chore number %d is outside the range of chores (0-%d)", num, _numChores); + return; + } _chores[num]->setLastFrame(); } void Costume::setChoreLooping(int num, bool val) { + if (num < 0 || num >= _numChores) { + Debug::warning(Debug::Chores, "Requested chore number %d is outside the range of chores (0-%d)", num, _numChores); + return; + } _chores[num]->setLooping(val); } @@ -481,11 +489,9 @@ void Costume::stopChores() { } void Costume::fadeChoreIn(int chore, int msecs) { - if (chore >= _numChores) { - if (chore < 0 || chore >= _numChores) { - Debug::warning(Debug::Chores, "Requested chore number %d is outside the range of chores (0-%d)", chore, _numChores); - return; - } + if (chore < 0 || chore >= _numChores) { + Debug::warning(Debug::Chores, "Requested chore number %d is outside the range of chores (0-%d)", chore, _numChores); + return; } _chores[chore]->fadeIn(msecs); if (Common::find(_playingChores.begin(), _playingChores.end(), _chores[chore]) == _playingChores.end()) @@ -493,11 +499,9 @@ void Costume::fadeChoreIn(int chore, int msecs) { } void Costume::fadeChoreOut(int chore, int msecs) { - if (chore >= _numChores) { - if (chore < 0 || chore >= _numChores) { - Debug::warning(Debug::Chores, "Requested chore number %d is outside the range of chores (0-%d)", chore, _numChores); - return; - } + if (chore < 0 || chore >= _numChores) { + Debug::warning(Debug::Chores, "Requested chore number %d is outside the range of chores (0-%d)", chore, _numChores); + return; } _chores[chore]->fadeOut(msecs); } @@ -511,6 +515,10 @@ int Costume::isChoring(const char *name, bool excludeLooping) { } int Costume::isChoring(int num, bool excludeLooping) { + if (num < 0 || num >= _numChores) { + Debug::warning(Debug::Chores, "Requested chore number %d is outside the range of chores (0-%d)", num, _numChores); + return -1; + } if (_chores[num]->_playing && !(excludeLooping && _chores[num]->_looping)) return num; else diff --git a/graphics/tinygl/light.cpp b/graphics/tinygl/light.cpp index 9ee025c8f18..a4d3823e28b 100644 --- a/graphics/tinygl/light.cpp +++ b/graphics/tinygl/light.cpp @@ -294,9 +294,11 @@ void gl_shade_vertex(GLContext *c, GLVertex *v) { // testing specular buffer code // dot_spec= pow(dot_spec,m->shininess) specbuf = specbuf_get_buffer(c, m->shininess_i, m->shininess); - idx = (int)(dot_spec * SPECULAR_BUFFER_SIZE); - if (idx > SPECULAR_BUFFER_SIZE) + tmp = dot_spec * SPECULAR_BUFFER_SIZE; + if (tmp > SPECULAR_BUFFER_SIZE) idx = SPECULAR_BUFFER_SIZE; + else + idx = (int)tmp; dot_spec = specbuf->buf[idx]; lR += dot_spec * l->specular.v[0] * m->specular.v[0];