aboutsummaryrefslogtreecommitdiff
path: root/engines/mutationofjb/util.h
diff options
context:
space:
mode:
authorĽubomír Remák2018-08-01 22:32:06 +0200
committerEugene Sandulenko2018-08-25 23:12:01 +0200
commitcd15dd82a252c3bca1f96a96c4d2c5a2bf4387d9 (patch)
tree4cdfcf55226a34fe16e97c9af43be5fca527fdff /engines/mutationofjb/util.h
parent4fbbaf944a392d67047dac64835f37cfcf518ecf (diff)
downloadscummvm-rg350-cd15dd82a252c3bca1f96a96c4d2c5a2bf4387d9.tar.gz
scummvm-rg350-cd15dd82a252c3bca1f96a96c4d2c5a2bf4387d9.tar.bz2
scummvm-rg350-cd15dd82a252c3bca1f96a96c4d2c5a2bf4387d9.zip
MUTATIONOFJB: Check for out of bounds destination in blit_if.
Diffstat (limited to 'engines/mutationofjb/util.h')
-rw-r--r--engines/mutationofjb/util.h15
1 files changed, 12 insertions, 3 deletions
diff --git a/engines/mutationofjb/util.h b/engines/mutationofjb/util.h
index 51c532b814..ac1239ddf7 100644
--- a/engines/mutationofjb/util.h
+++ b/engines/mutationofjb/util.h
@@ -38,8 +38,13 @@ namespace MutationOfJB {
void reportFileMissingError(const char *fileName);
Common::String toUpperCP895(const Common::String &str);
+// Taken from ManagedSurface::clip.
template <typename SurfaceType>
-void clipBounds(Common::Rect &srcBounds, Common::Rect &destBounds, SurfaceType &destSurf) {
+bool clipBounds(Common::Rect &srcBounds, Common::Rect &destBounds, SurfaceType &destSurf) {
+ if (destBounds.left >= destSurf.w || destBounds.top >= destSurf.h ||
+ destBounds.right <= 0 || destBounds.bottom <= 0)
+ return false;
+
// Clip the bounds if source is too big to fit into destination.
if (destBounds.right > destSurf.w) {
srcBounds.right -= destBounds.right - destSurf.w;
@@ -60,6 +65,8 @@ void clipBounds(Common::Rect &srcBounds, Common::Rect &destBounds, SurfaceType &
srcBounds.left += -destBounds.left;
destBounds.left = 0;
}
+
+ return true;
}
template <typename BlitOp>
@@ -70,7 +77,8 @@ void blit_if(const Graphics::Surface &src, const Common::Rect &srcRect, Graphics
assert(srcRect.isValidRect());
assert(dest.format == src.format);
- clipBounds(srcBounds, destBounds, dest);
+ if (!clipBounds(srcBounds, destBounds, dest))
+ return;
for (int y = 0; y < srcBounds.height(); ++y) {
const byte *srcP = reinterpret_cast<const byte *>(src.getBasePtr(srcBounds.left, srcBounds.top + y));
@@ -96,7 +104,8 @@ void blit_if(const Graphics::Surface &src, const Common::Rect &srcRect, Graphics
assert(srcRect.isValidRect());
assert(dest.format == src.format);
- clipBounds(srcBounds, destBounds, dest);
+ if (!clipBounds(srcBounds, destBounds, dest))
+ return;
Graphics::Surface destSurf = dest.getSubArea(destBounds); // This will invalidate the rectangle.
blit_if(src, srcRect, destSurf, Common::Point(0, 0), blitOp);