[Scummvm-cvs-logs] SF.net SVN: scummvm:[55547] scummvm/trunk/engines/gob

drmccoy at users.sourceforge.net drmccoy at users.sourceforge.net
Wed Jan 26 20:03:13 CET 2011


Revision: 55547
          http://scummvm.svn.sourceforge.net/scummvm/?rev=55547&view=rev
Author:   drmccoy
Date:     2011-01-26 19:03:13 +0000 (Wed, 26 Jan 2011)

Log Message:
-----------
GOB: Check font index for kFontCount

Modified Paths:
--------------
    scummvm/trunk/engines/gob/draw.cpp
    scummvm/trunk/engines/gob/draw.h
    scummvm/trunk/engines/gob/draw_v1.cpp
    scummvm/trunk/engines/gob/draw_v2.cpp
    scummvm/trunk/engines/gob/inter_v1.cpp

Modified: scummvm/trunk/engines/gob/draw.cpp
===================================================================
--- scummvm/trunk/engines/gob/draw.cpp	2011-01-26 19:02:39 UTC (rev 55546)
+++ scummvm/trunk/engines/gob/draw.cpp	2011-01-26 19:03:13 UTC (rev 55547)
@@ -371,12 +371,17 @@
 	}
 }
 
-int Draw::stringLength(const char *str, int16 fontIndex) {
+int Draw::stringLength(const char *str, uint16 fontIndex) {
 	static const int8 japaneseExtraCharLen[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
 
-	if ((fontIndex < 0) || (fontIndex > 7) || !_fonts[fontIndex])
+	if (fontIndex >= kFontCount) {
+		warning("Draw::stringLength(): Font %d > Count %d", fontIndex, kFontCount);
 		return 0;
+	}
 
+	if (!_fonts[fontIndex])
+		return 0;
+
 	Font &font = *_fonts[fontIndex];
 
 	int len = 0;
@@ -442,6 +447,14 @@
 	if (str[0] == '\0')
 		return;
 
+	if (fontIndex >= kFontCount) {
+		warning("Draw::printTextCentered(): Font %d > Count %d", fontIndex, kFontCount);
+		return;
+	}
+
+	if (!_fonts[fontIndex])
+		return;
+
 	_transparency = 1;
 	_destSpriteX = left;
 	_destSpriteY = top;
@@ -503,6 +516,14 @@
 
 	strcpy(paramStr, tmpStr);
 
+	if (fontIndex >= kFontCount) {
+		warning("Draw::oPlaytoons_sub_F_1B(): Font %d > Count %d", fontIndex, kFontCount);
+		return;
+	}
+
+	if (!_fonts[fontIndex])
+		return;
+
 	if (*paramStr) {
 		_transparency = 1;
 		_fontIndex = fontIndex;
@@ -673,9 +694,11 @@
 	return new Font(data);
 }
 
-bool Draw::loadFont(int fontIndex, const char *path) {
-	if ((fontIndex < 0) || (fontIndex >= kFontCount))
+bool Draw::loadFont(uint16 fontIndex, const char *path) {
+	if (fontIndex >= kFontCount) {
+		warning("Draw::loadFont(): Font %d > Count %d (\"%s\")", fontIndex, kFontCount, path);
 		return false;
+	}
 
 	delete _fonts[fontIndex];
 

Modified: scummvm/trunk/engines/gob/draw.h
===================================================================
--- scummvm/trunk/engines/gob/draw.h	2011-01-26 19:02:39 UTC (rev 55546)
+++ scummvm/trunk/engines/gob/draw.h	2011-01-26 19:03:13 UTC (rev 55547)
@@ -71,7 +71,7 @@
 
 	int16 _renderFlags;
 
-	int16 _fontIndex;
+	uint16 _fontIndex;
 	int16 _spriteLeft;
 	int16 _spriteTop;
 	int16 _spriteRight;
@@ -184,7 +184,7 @@
 	void adjustCoords(char adjust, uint16 *coord1, uint16 *coord2) {
 		adjustCoords(adjust, (int16 *)coord1, (int16 *)coord2);
 	}
-	int stringLength(const char *str, int16 fontIndex);
+	int stringLength(const char *str, uint16 fontIndex);
 	void drawString(const char *str, int16 x, int16 y, int16 color1, int16 color2,
 			int16 transp, Surface &dest, const Font &font);
 	void printTextCentered(int16 id, int16 left, int16 top, int16 right,
@@ -198,7 +198,7 @@
 	void wobble(Surface &surfDesc);
 
 	Font *loadFont(const char *path) const;
-	bool loadFont(int fontIndex, const char *path);
+	bool loadFont(uint16 fontIndex, const char *path);
 
 	virtual void initScreen() = 0;
 	virtual void closeScreen() = 0;

Modified: scummvm/trunk/engines/gob/draw_v1.cpp
===================================================================
--- scummvm/trunk/engines/gob/draw_v1.cpp	2011-01-26 19:02:39 UTC (rev 55546)
+++ scummvm/trunk/engines/gob/draw_v1.cpp	2011-01-26 19:03:13 UTC (rev 55547)
@@ -247,8 +247,7 @@
 		if (*ptr != 0xBA) {
 			_letterToPrint = (char) *ptr;
 			spriteOperation(DRAW_DRAWLETTER);
-			_destSpriteX +=
-			    _fonts[_fontIndex]->getCharWidth();
+			_destSpriteX += _fonts[_fontIndex]->getCharWidth();
 			ptr++;
 		} else {
 			cmd = ptrEnd[17] & 0x7F;
@@ -401,12 +400,12 @@
 		break;
 
 	case DRAW_PRINTTEXT:
-		font = _fonts[_fontIndex];
-		if (!font) {
+		if ((_fontIndex >= kFontCount) || !_fonts[_fontIndex]) {
 			warning("Trying to print \"%s\" with undefined font %d", _textToPrint, _fontIndex);
 			break;
 		}
 
+		font = _fonts[_fontIndex];
 		len = strlen(_textToPrint);
 		dirtiedRect(_destSurface, _destSpriteX, _destSpriteY,
 				_destSpriteX + len * font->getCharWidth() - 1,
@@ -453,12 +452,12 @@
 		break;
 
 	case DRAW_DRAWLETTER:
-		font = _fonts[_fontIndex];
-		if (!font) {
+		if ((_fontIndex >= kFontCount) || !_fonts[_fontIndex]) {
 			warning("Trying to print \'%c\' with undefined font %d", _letterToPrint, _fontIndex);
 			break;
 		}
 
+		font = _fonts[_fontIndex];
 		if (_fontToSprite[_fontIndex].sprite == -1) {
 			dirtiedRect(_destSurface, _destSpriteX, _destSpriteY,
 					_destSpriteX + font->getCharWidth()  - 1,

Modified: scummvm/trunk/engines/gob/draw_v2.cpp
===================================================================
--- scummvm/trunk/engines/gob/draw_v2.cpp	2011-01-26 19:02:39 UTC (rev 55546)
+++ scummvm/trunk/engines/gob/draw_v2.cpp	2011-01-26 19:03:13 UTC (rev 55547)
@@ -788,12 +788,12 @@
 		left = _destSpriteX;
 
 		if ((_fontIndex >= 4) || (_fontToSprite[_fontIndex].sprite == -1)) {
-			Font *font = _fonts[_fontIndex];
-			if (!font) {
+			if ((_fontIndex >= kFontCount) || !_fonts[_fontIndex]) {
 				warning("Trying to print \"%s\" with undefined font %d", _textToPrint, _fontIndex);
 				break;
 			}
 
+			Font *font = _fonts[_fontIndex];
 			if (font->isMonospaced()) {
 				if (((int8) _textToPrint[0]) == -1) {
 					_vm->validateLanguage();

Modified: scummvm/trunk/engines/gob/inter_v1.cpp
===================================================================
--- scummvm/trunk/engines/gob/inter_v1.cpp	2011-01-26 19:02:39 UTC (rev 55546)
+++ scummvm/trunk/engines/gob/inter_v1.cpp	2011-01-26 19:03:13 UTC (rev 55547)
@@ -1746,10 +1746,8 @@
 }
 
 bool Inter_v1::o1_loadFont(OpFuncParams &params) {
-	int16 index;
-
 	_vm->_game->_script->evalExpr(0);
-	index = _vm->_game->_script->readInt16();
+	uint16 index = _vm->_game->_script->readInt16();
 
 	_vm->_draw->animateCursor(4);
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list