[Scummvm-git-logs] scummvm master -> 573c10f0c8848570d9f6ef3d9c29304c9e70266a

antoniou79 a.antoniou79 at gmail.com
Fri Feb 28 09:00:56 UTC 2020


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:
573c10f0c8 TOON: Prevent segmentation fault if PAK file is missing


Commit: 573c10f0c8848570d9f6ef3d9c29304c9e70266a
    https://github.com/scummvm/scummvm/commit/573c10f0c8848570d9f6ef3d9c29304c9e70266a
Author: Thanasis Antoniou (a.antoniou79 at gmail.com)
Date: 2020-02-28T10:57:53+02:00

Commit Message:
TOON: Prevent segmentation fault if PAK file is missing

Could be related to ticket #11319

https://bugs.scummvm.org/ticket/11319

Changed paths:
    engines/toon/picture.cpp
    engines/toon/resource.cpp
    engines/toon/resource.h
    engines/toon/toon.cpp


diff --git a/engines/toon/picture.cpp b/engines/toon/picture.cpp
index 4d9e45aacd..8901a4b6da 100644
--- a/engines/toon/picture.cpp
+++ b/engines/toon/picture.cpp
@@ -62,7 +62,7 @@ bool Picture::loadPicture(const Common::String &file) {
 			memcpy(_palette, _data + dstsize - (dstsize & 0x7ff), _paletteEntries * 3);
 			_vm->fixPaletteEntries(_palette, _paletteEntries);
 		} else {
-			_palette = 0;
+			_palette = NULL;
 		}
 		return true;
 	}
@@ -76,6 +76,8 @@ bool Picture::loadPicture(const Common::String &file) {
 			_palette = new uint8[_paletteEntries * 3];
 			memcpy(_palette, fileData + 16, _paletteEntries * 3);
 			_vm->fixPaletteEntries(_palette, _paletteEntries);
+		} else {
+			_palette = NULL;
 		}
 
 		// size can only be 640x400 or 1280x400
@@ -151,10 +153,12 @@ Picture::~Picture() {
 void Picture::setupPalette() {
 	debugC(1, kDebugPicture, "setupPalette()");
 
-	if (_useFullPalette)
-		_vm->setPaletteEntries(_palette, 0, 256);
-	else
-		_vm->setPaletteEntries(_palette, 1, 128);
+	if (_palette != NULL) {
+		if (_useFullPalette)
+			_vm->setPaletteEntries(_palette, 0, 256);
+		else
+			_vm->setPaletteEntries(_palette, 1, 128);
+	}
 }
 
 void Picture::drawMask(Graphics::Surface &surface, int16 x, int16 y, int16 dx, int16 dy) {
diff --git a/engines/toon/resource.cpp b/engines/toon/resource.cpp
index 3dbb6557fd..8629d4776b 100644
--- a/engines/toon/resource.cpp
+++ b/engines/toon/resource.cpp
@@ -115,14 +115,14 @@ void Resources::addToCache(const Common::String &packName, const Common::String
 	_resourceCache.push_back(entry);
 }
 
-void Resources::openPackage(const Common::String &fileName) {
+bool Resources::openPackage(const Common::String &fileName) {
 	debugC(1, kDebugResource, "openPackage(%s)", fileName.c_str());
 
 	Common::File file;
 	bool opened = file.open(fileName);
 
 	if (!opened)
-		return;
+		return false;
 
 	PakFile *pakFile = new PakFile();
 	pakFile->open(&file, fileName);
@@ -130,6 +130,7 @@ void Resources::openPackage(const Common::String &fileName) {
 	file.close();
 
 	_pakFiles.push_back(pakFile);
+	return true;
 }
 
 void Resources::closePackage(const Common::String &fileName) {
diff --git a/engines/toon/resource.h b/engines/toon/resource.h
index 6991fae5a7..d1827c1c65 100644
--- a/engines/toon/resource.h
+++ b/engines/toon/resource.h
@@ -75,7 +75,7 @@ class Resources {
 public:
 	Resources(ToonEngine *vm);
 	~Resources();
-	void openPackage(const Common::String &file);
+	bool openPackage(const Common::String &file);
 	void closePackage(const Common::String &fileName);
 	Common::SeekableReadStream *openFile(const Common::String &file);
 	uint8 *getFileData(const Common::String &fileName, uint32 *fileSize); // this memory must be copied to your own structures!
diff --git a/engines/toon/toon.cpp b/engines/toon/toon.cpp
index 90f62a2e9f..0f2e0da9c8 100644
--- a/engines/toon/toon.cpp
+++ b/engines/toon/toon.cpp
@@ -1523,7 +1523,13 @@ void ToonEngine::loadScene(int32 SceneId, bool forGameLoad) {
 	Common::String locationName = state()->_locations[SceneId]._name;
 
 	// load package
-	resources()->openPackage(createRoomFilename(locationName + ".PAK"));
+	if (!resources()->openPackage(createRoomFilename(locationName + ".PAK"))) {
+		Common::String msg = Common::String::format(_("Unable to locate the '%s' data file."), createRoomFilename(locationName + ".PAK").c_str());
+		GUIErrorMessage(msg);
+		warning("%s", msg.c_str());
+		_shouldQuit = true;
+		return;
+	}
 
 	loadAdditionalPalette(locationName + ".NPP", 0);
 




More information about the Scummvm-git-logs mailing list