diff options
author | Colin Snover | 2016-05-27 18:59:12 -0500 |
---|---|---|
committer | Colin Snover | 2016-05-27 19:20:22 -0500 |
commit | 371b50e75abec89ed182a72599d96b645711bbc8 (patch) | |
tree | d69d2ae4c15b460e22d1979d884fbec25c39e577 /engines/sci/graphics | |
parent | 4840b889d7c8d2924f162c270d85c5431f0f86a6 (diff) | |
download | scummvm-rg350-371b50e75abec89ed182a72599d96b645711bbc8.tar.gz scummvm-rg350-371b50e75abec89ed182a72599d96b645711bbc8.tar.bz2 scummvm-rg350-371b50e75abec89ed182a72599d96b645711bbc8.zip |
SCI32: Add explicit checks for null pointers
CID 1351617, 1351618, 1351619, 1351620, 1351621, 1351622, 1354791.
Diffstat (limited to 'engines/sci/graphics')
-rw-r--r-- | engines/sci/graphics/celobj32.cpp | 24 | ||||
-rw-r--r-- | engines/sci/graphics/frameout.cpp | 4 | ||||
-rw-r--r-- | engines/sci/graphics/screen_item32.cpp | 6 |
3 files changed, 28 insertions, 6 deletions
diff --git a/engines/sci/graphics/celobj32.cpp b/engines/sci/graphics/celobj32.cpp index da00a5e17c..77d333a717 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 6454a1eb32..3903e7b698 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 953091470f..fba0fa0422 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. |