diff options
author | Littleboy | 2011-06-23 05:42:48 -0400 |
---|---|---|
committer | Littleboy | 2011-06-23 08:52:52 -0400 |
commit | b694a78f62a02253bca2a5611314599ae7fce725 (patch) | |
tree | 115573b00e3b025ed334f9eadeadfb6161286089 /common | |
parent | 7a96e0bfb67e9b5b8c0aa9bdae8415fb98214c3f (diff) | |
download | scummvm-rg350-b694a78f62a02253bca2a5611314599ae7fce725.tar.gz scummvm-rg350-b694a78f62a02253bca2a5611314599ae7fce725.tar.bz2 scummvm-rg350-b694a78f62a02253bca2a5611314599ae7fce725.zip |
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
Diffstat (limited to 'common')
-rw-r--r-- | common/config-file.cpp | 6 | ||||
-rw-r--r-- | common/config-manager.cpp | 6 | ||||
-rw-r--r-- | common/str.cpp | 6 | ||||
-rw-r--r-- | common/xmlparser.cpp | 10 | ||||
-rw-r--r-- | common/xmlparser.h | 2 |
5 files changed, 15 insertions, 15 deletions
diff --git a/common/config-file.cpp b/common/config-file.cpp index 55941131ac..ea3feff8ae 100644 --- a/common/config-file.cpp +++ b/common/config-file.cpp @@ -38,7 +38,7 @@ namespace Common { */ bool ConfigFile::isValidName(const Common::String &name) { const char *p = name.c_str(); - while (*p && (isalnum(*p) || *p == '-' || *p == '_' || *p == '.')) + while (*p && (isalnum(static_cast<unsigned char>(*p)) || *p == '-' || *p == '_' || *p == '.')) p++; return *p == 0; } @@ -116,7 +116,7 @@ bool ConfigFile::loadFromStream(SeekableReadStream &stream) { // is, verify that it only consists of alphanumerics, // periods, dashes and underscores). Mohawk Living Books games // can have periods in their section names. - while (*p && (isalnum(*p) || *p == '-' || *p == '_' || *p == '.')) + while (*p && (isalnum(static_cast<unsigned char>(*p)) || *p == '-' || *p == '_' || *p == '.')) p++; if (*p == '\0') @@ -139,7 +139,7 @@ bool ConfigFile::loadFromStream(SeekableReadStream &stream) { // Skip leading whitespaces const char *t = line.c_str(); - while (isspace(*t)) + while (isspace(static_cast<unsigned char>(*t))) t++; // Skip empty lines / lines with only whitespace diff --git a/common/config-manager.cpp b/common/config-manager.cpp index 3941e27cc1..a9d8c89035 100644 --- a/common/config-manager.cpp +++ b/common/config-manager.cpp @@ -31,7 +31,7 @@ DECLARE_SINGLETON(Common::ConfigManager); static bool isValidDomainName(const Common::String &domName) { const char *p = domName.c_str(); - while (*p && (isalnum(*p) || *p == '-' || *p == '_')) + while (*p && (isalnum(static_cast<unsigned char>(*p)) || *p == '-' || *p == '_')) p++; return *p == 0; } @@ -187,7 +187,7 @@ void ConfigManager::loadFromStream(SeekableReadStream &stream) { // Get the domain name, and check whether it's valid (that // is, verify that it only consists of alphanumerics, // dashes and underscores). - while (*p && (isalnum(*p) || *p == '-' || *p == '_')) + while (*p && (isalnum(static_cast<unsigned char>(*p)) || *p == '-' || *p == '_')) p++; if (*p == '\0') @@ -205,7 +205,7 @@ void ConfigManager::loadFromStream(SeekableReadStream &stream) { // Skip leading whitespaces const char *t = line.c_str(); - while (isspace(*t)) + while (isspace(static_cast<unsigned char>(*t))) t++; // Skip empty lines / lines with only whitespace diff --git a/common/str.cpp b/common/str.cpp index a2cd4a0193..32f4b44e79 100644 --- a/common/str.cpp +++ b/common/str.cpp @@ -405,7 +405,7 @@ void String::trim() { makeUnique(); // Trim trailing whitespace - while (_size >= 1 && isspace(_str[_size - 1])) + while (_size >= 1 && isspace(static_cast<unsigned char>(_str[_size - 1]))) --_size; _str[_size] = 0; @@ -606,14 +606,14 @@ String operator+(const String &x, char y) { } char *ltrim(char *t) { - while (isspace(*t)) + while (isspace(static_cast<unsigned char>(*t))) t++; return t; } char *rtrim(char *t) { int l = strlen(t) - 1; - while (l >= 0 && isspace(t[l])) + while (l >= 0 && isspace(static_cast<unsigned char>(t[l]))) t[l--] = 0; return t; } diff --git a/common/xmlparser.cpp b/common/xmlparser.cpp index 5217c4e82c..623619914a 100644 --- a/common/xmlparser.cpp +++ b/common/xmlparser.cpp @@ -263,7 +263,7 @@ bool XMLParser::vparseIntegerKey(const char *key, int count, va_list args) { int *num_ptr; while (count--) { - while (isspace(*key)) + while (isspace(static_cast<unsigned char>(*key))) key++; num_ptr = va_arg(args, int*); @@ -271,7 +271,7 @@ bool XMLParser::vparseIntegerKey(const char *key, int count, va_list args) { key = parseEnd; - while (isspace(*key)) + while (isspace(static_cast<unsigned char>(*key))) key++; if (count && *key++ != ',') @@ -463,10 +463,10 @@ bool XMLParser::parse() { } bool XMLParser::skipSpaces() { - if (!isspace(_char)) + if (!isspace(static_cast<unsigned char>(_char))) return false; - while (_char && isspace(_char)) + while (_char && isspace(static_cast<unsigned char>(_char))) _char = _stream->readByte(); return true; @@ -516,7 +516,7 @@ bool XMLParser::parseToken() { _char = _stream->readByte(); } - return isspace(_char) != 0 || _char == '>' || _char == '=' || _char == '/'; + return isspace(static_cast<unsigned char>(_char)) != 0 || _char == '>' || _char == '=' || _char == '/'; } } // End of namespace Common diff --git a/common/xmlparser.h b/common/xmlparser.h index 7923e43a37..40c779b87e 100644 --- a/common/xmlparser.h +++ b/common/xmlparser.h @@ -294,7 +294,7 @@ protected: * in their name. */ virtual inline bool isValidNameChar(char c) { - return isalnum(c) || c == '_'; + return isalnum(static_cast<unsigned char>(c)) || c == '_'; } /** |