From b694a78f62a02253bca2a5611314599ae7fce725 Mon Sep 17 00:00:00 2001 From: Littleboy Date: Thu, 23 Jun 2011 05:42:48 -0400 Subject: ANALYSIS: Add static casts to is* functions This fixes a potential problem with passing char values that would be sign-extended and yield unexpected results. See http://msdn.microsoft.com/en-us/library/ms245348.aspx --- engines/sci/engine/kstring.cpp | 4 ++-- engines/sci/graphics/text16.cpp | 2 +- engines/sci/resource.cpp | 4 ++-- engines/sci/resource_audio.cpp | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) (limited to 'engines/sci') diff --git a/engines/sci/engine/kstring.cpp b/engines/sci/engine/kstring.cpp index 07b87a7cbc..9f10691767 100644 --- a/engines/sci/engine/kstring.cpp +++ b/engines/sci/engine/kstring.cpp @@ -238,14 +238,14 @@ reg_t kFormat(EngineState *s, int argc, reg_t *argv) { /* int writelength; -- unused atm */ - if (xfer && (isdigit(xfer) || xfer == '-' || xfer == '=')) { + if (xfer && (isdigit(static_cast(xfer)) || xfer == '-' || xfer == '=')) { char *destp; if (xfer == '0') fillchar = '0'; else if (xfer == '=') align = ALIGN_CENTER; - else if (isdigit(xfer) || (xfer == '-')) + else if (isdigit(static_cast(xfer)) || (xfer == '-')) source--; // Go to start of length argument str_leng = strtol(source, &destp, 10); diff --git a/engines/sci/graphics/text16.cpp b/engines/sci/graphics/text16.cpp index c2f71a0e54..84547d9828 100644 --- a/engines/sci/graphics/text16.cpp +++ b/engines/sci/graphics/text16.cpp @@ -100,7 +100,7 @@ int16 GfxText16::CodeProcessing(const char *&text, GuiResourceId orgFontId, int1 // cX -> sets textColor to _textColors[X-1] curCode = textCode[0]; curCodeParm = textCode[1]; - if (isdigit(curCodeParm)) { + if (isdigit(static_cast(curCodeParm))) { curCodeParm -= '0'; } else { curCodeParm = -1; diff --git a/engines/sci/resource.cpp b/engines/sci/resource.cpp index fa70481bdc..f18b6c91f5 100644 --- a/engines/sci/resource.cpp +++ b/engines/sci/resource.cpp @@ -1555,7 +1555,7 @@ void ResourceManager::readResourcePatches() { name = (*x)->getName(); // SCI1 scheme - if (isdigit(name[0])) { + if (isdigit(static_cast(name[0]))) { char *end = 0; resourceNr = strtol(name.c_str(), &end, 10); bAdd = (*end == '.'); // Ensure the next character is the period @@ -1563,7 +1563,7 @@ void ResourceManager::readResourcePatches() { // SCI0 scheme int resname_len = strlen(szResType); if (scumm_strnicmp(name.c_str(), szResType, resname_len) == 0 - && !isalpha(name[resname_len + 1])) { + && !isalpha(static_cast(name[resname_len + 1]))) { resourceNr = atoi(name.c_str() + resname_len + 1); bAdd = true; } diff --git a/engines/sci/resource_audio.cpp b/engines/sci/resource_audio.cpp index 032040fc2c..f3a3c8dd5b 100644 --- a/engines/sci/resource_audio.cpp +++ b/engines/sci/resource_audio.cpp @@ -197,7 +197,7 @@ void ResourceManager::readWaveAudioPatches() { for (Common::ArchiveMemberList::const_iterator x = files.begin(); x != files.end(); ++x) { Common::String name = (*x)->getName(); - if (isdigit(name[0])) + if (isdigit(static_cast(name[0]))) processWavePatch(ResourceId(kResourceTypeAudio, atoi(name.c_str())), name); } } -- cgit v1.2.3