[Scummvm-cvs-logs] scummvm master -> 371b50e75abec89ed182a72599d96b645711bbc8

csnover csnover at users.noreply.github.com
Sat May 28 02:22:53 CEST 2016


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
371b50e75a SCI32: Add explicit checks for null pointers


Commit: 371b50e75abec89ed182a72599d96b645711bbc8
    https://github.com/scummvm/scummvm/commit/371b50e75abec89ed182a72599d96b645711bbc8
Author: Colin Snover (github.com at zetafleet.com)
Date: 2016-05-27T19:20:22-05:00

Commit Message:
SCI32: Add explicit checks for null pointers

CID 1351617, 1351618, 1351619, 1351620, 1351621, 1351622, 1354791.

Changed paths:
    engines/sci/engine/kgraphics32.cpp
    engines/sci/graphics/celobj32.cpp
    engines/sci/graphics/frameout.cpp
    engines/sci/graphics/screen_item32.cpp



diff --git a/engines/sci/engine/kgraphics32.cpp b/engines/sci/engine/kgraphics32.cpp
index d5540f7..6c51ec4 100644
--- a/engines/sci/engine/kgraphics32.cpp
+++ b/engines/sci/engine/kgraphics32.cpp
@@ -216,6 +216,9 @@ reg_t kTextSize32(EngineState *s, int argc, reg_t *argv) {
 	g_sci->_gfxText32->setFont(argv[2].toUint16());
 
 	reg_t *rect = s->_segMan->derefRegPtr(argv[0], 4);
+	if (rect == nullptr) {
+		error("kTextSize: %04x:%04x cannot be dereferenced", PRINT_REG(argv[0]));
+	}
 
 	Common::String text = s->_segMan->getString(argv[1]);
 	int16 maxWidth = argc > 3 ? argv[3].toSint16() : 0;
diff --git a/engines/sci/graphics/celobj32.cpp b/engines/sci/graphics/celobj32.cpp
index da00a5e..77d333a 100644
--- a/engines/sci/graphics/celobj32.cpp
+++ b/engines/sci/graphics/celobj32.cpp
@@ -736,7 +736,11 @@ CelObjView::CelObjView(const GuiResourceId viewId, const int16 loopNo, const int
 	int cacheIndex = searchCache(_info, &cacheInsertIndex);
 	if (cacheIndex != -1) {
 		CelCacheEntry &entry = (*_cache)[cacheIndex];
-		*this = *dynamic_cast<CelObjView *>(entry.celObj);
+		const CelObjView *const cachedCelObj = dynamic_cast<CelObjView *>(entry.celObj);
+		if (cachedCelObj == nullptr) {
+			error("Expected a CelObjView in cache slot %d", cacheIndex);
+		}
+		*this = *cachedCelObj;
 		entry.id = ++_nextCacheId;
 		return;
 	}
@@ -868,7 +872,11 @@ CelObjView *CelObjView::duplicate() const {
 }
 
 byte *CelObjView::getResPointer() const {
-	return g_sci->getResMan()->findResource(ResourceId(kResourceTypeView, _info.resourceId), false)->data;
+	const Resource *const resource = g_sci->getResMan()->findResource(ResourceId(kResourceTypeView, _info.resourceId), false);
+	if (resource == nullptr) {
+		error("Failed to load view %d from resource manager", _info.resourceId);
+	}
+	return resource->data;
 }
 
 #pragma mark -
@@ -887,7 +895,11 @@ CelObjPic::CelObjPic(const GuiResourceId picId, const int16 celNo) {
 	int cacheIndex = searchCache(_info, &cacheInsertIndex);
 	if (cacheIndex != -1) {
 		CelCacheEntry &entry = (*_cache)[cacheIndex];
-		*this = *dynamic_cast<CelObjPic *>(entry.celObj);
+		const CelObjPic *const cachedCelObj = dynamic_cast<CelObjPic *>(entry.celObj);
+		if (cachedCelObj == nullptr) {
+			error("Expected a CelObjPic in cache slot %d", cacheIndex);
+		}
+		*this = *cachedCelObj;
 		entry.id = ++_nextCacheId;
 		return;
 	}
@@ -981,7 +993,11 @@ CelObjPic *CelObjPic::duplicate() const {
 }
 
 byte *CelObjPic::getResPointer() const {
-	return g_sci->getResMan()->findResource(ResourceId(kResourceTypePic, _info.resourceId), false)->data;
+	const Resource *const resource = g_sci->getResMan()->findResource(ResourceId(kResourceTypePic, _info.resourceId), false);
+	if (resource == nullptr) {
+		error("Failed to load pic %d from resource manager", _info.resourceId);
+	}
+	return resource->data;
 }
 
 #pragma mark -
diff --git a/engines/sci/graphics/frameout.cpp b/engines/sci/graphics/frameout.cpp
index 6454a1e..3903e7b 100644
--- a/engines/sci/graphics/frameout.cpp
+++ b/engines/sci/graphics/frameout.cpp
@@ -680,7 +680,7 @@ void GfxFrameout::calcLists(ScreenItemListList &drawLists, EraseListList &eraseL
 					int splitCount = splitRects(*rectlist[rectIndex], _planes[innerIndex]->_screenRect, outRects);
 
 					if (splitCount == 0) {
-						if (visibleInnerPlane != nullptr) {
+						if (visibleInnerPlane != nullptr && visibleOuterPlane != nullptr) {
 							// same priority, or relative priority between inner/outer changed
 							if ((visibleOuterPlane->_priority - visibleInnerPlane->_priority) * (outerPlane->_priority - innerPlane->_priority) <= 0) {
 								if (outerPlane->_priority <= innerPlane->_priority) {
@@ -697,7 +697,7 @@ void GfxFrameout::calcLists(ScreenItemListList &drawLists, EraseListList &eraseL
 							rectlist.add(outRects[i]);
 						}
 
-						if (visibleInnerPlane != nullptr) {
+						if (visibleInnerPlane != nullptr && visibleOuterPlane != nullptr) {
 							// same priority, or relative priority between inner/outer changed
 							if ((visibleOuterPlane->_priority - visibleInnerPlane->_priority) * (outerPlane->_priority - innerPlane->_priority) <= 0) {
 								*rectlist[rectIndex] = outerPlane->_screenRect.findIntersectingRect(innerPlane->_screenRect);
diff --git a/engines/sci/graphics/screen_item32.cpp b/engines/sci/graphics/screen_item32.cpp
index 9530914..fba0fa0 100644
--- a/engines/sci/graphics/screen_item32.cpp
+++ b/engines/sci/graphics/screen_item32.cpp
@@ -326,6 +326,9 @@ void ScreenItem::calcRects(const Plane &plane) {
 				mulinc(temp, celToScreenX, Ratio());
 
 				CelObjPic *celObjPic = dynamic_cast<CelObjPic *>(_celObj);
+				if (celObjPic == nullptr) {
+					error("Expected a CelObjPic");
+				}
 				temp.translate((celObjPic->_relativePosition.x * scriptToScreenX).toInt() - displaceX, 0);
 
 				// TODO: This is weird.
@@ -369,6 +372,9 @@ void ScreenItem::calcRects(const Plane &plane) {
 				}
 
 				CelObjPic *celObjPic = dynamic_cast<CelObjPic *>(_celObj);
+				if (celObjPic == nullptr) {
+					error("Expected a CelObjPic");
+				}
 				temp.translate(celObjPic->_relativePosition.x - (displaceX * scaleX).toInt(), celObjPic->_relativePosition.y - (celObj._displace.y * scaleY).toInt());
 
 				// TODO: This is weird.






More information about the Scummvm-git-logs mailing list