aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSven Hesse2011-01-26 19:03:13 +0000
committerSven Hesse2011-01-26 19:03:13 +0000
commita2afc0f4d19f8eff5e9ebc49d51035970d4bcb8c (patch)
tree7127d56d027982fbc88a36b19e8397ea63a20f2c
parent2c2476b203c10699973950f08f6d8a4b3866408e (diff)
downloadscummvm-rg350-a2afc0f4d19f8eff5e9ebc49d51035970d4bcb8c.tar.gz
scummvm-rg350-a2afc0f4d19f8eff5e9ebc49d51035970d4bcb8c.tar.bz2
scummvm-rg350-a2afc0f4d19f8eff5e9ebc49d51035970d4bcb8c.zip
GOB: Check font index for kFontCount
svn-id: r55547
-rw-r--r--engines/gob/draw.cpp31
-rw-r--r--engines/gob/draw.h6
-rw-r--r--engines/gob/draw_v1.cpp11
-rw-r--r--engines/gob/draw_v2.cpp4
-rw-r--r--engines/gob/inter_v1.cpp4
5 files changed, 38 insertions, 18 deletions
diff --git a/engines/gob/draw.cpp b/engines/gob/draw.cpp
index f86d5e67c9..8b1d00b5d6 100644
--- a/engines/gob/draw.cpp
+++ b/engines/gob/draw.cpp
@@ -371,10 +371,15 @@ void Draw::adjustCoords(char adjust, int16 *coord1, int16 *coord2) {
}
}
-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];
@@ -442,6 +447,14 @@ void Draw::printTextCentered(int16 id, int16 left, int16 top, int16 right,
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 @@ void Draw::oPlaytoons_sub_F_1B(uint16 id, int16 left, int16 top, int16 right, in
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 @@ Font *Draw::loadFont(const char *path) const {
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];
diff --git a/engines/gob/draw.h b/engines/gob/draw.h
index 6a23994cf8..3f69337e97 100644
--- a/engines/gob/draw.h
+++ b/engines/gob/draw.h
@@ -71,7 +71,7 @@ public:
int16 _renderFlags;
- int16 _fontIndex;
+ uint16 _fontIndex;
int16 _spriteLeft;
int16 _spriteTop;
int16 _spriteRight;
@@ -184,7 +184,7 @@ public:
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 @@ public:
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;
diff --git a/engines/gob/draw_v1.cpp b/engines/gob/draw_v1.cpp
index d130f424c2..e528b6ad86 100644
--- a/engines/gob/draw_v1.cpp
+++ b/engines/gob/draw_v1.cpp
@@ -247,8 +247,7 @@ void Draw_v1::printTotText(int16 id) {
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 @@ void Draw_v1::spriteOperation(int16 operation) {
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 @@ void Draw_v1::spriteOperation(int16 operation) {
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,
diff --git a/engines/gob/draw_v2.cpp b/engines/gob/draw_v2.cpp
index e31b1f8269..ee6f9132aa 100644
--- a/engines/gob/draw_v2.cpp
+++ b/engines/gob/draw_v2.cpp
@@ -788,12 +788,12 @@ void Draw_v2::spriteOperation(int16 operation) {
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();
diff --git a/engines/gob/inter_v1.cpp b/engines/gob/inter_v1.cpp
index 368a903496..b8c834c547 100644
--- a/engines/gob/inter_v1.cpp
+++ b/engines/gob/inter_v1.cpp
@@ -1746,10 +1746,8 @@ bool Inter_v1::o1_blitCursor(OpFuncParams &params) {
}
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);