Added missing casts causing assertion failures on Windows (#5391)

-> Changed much more occurences, especially in preprocessor.cpp.
This commit is contained in:
PKEuS 2014-03-18 21:41:47 +01:00
parent af922aedbf
commit b564986d5d
6 changed files with 35 additions and 35 deletions

View File

@ -380,7 +380,7 @@ void CheckIO::invalidScanf()
format = false; format = false;
} }
else if (std::isalpha(formatstr[i]) || formatstr[i] == '[') { else if (std::isalpha((unsigned char)formatstr[i]) || formatstr[i] == '[') {
if ((formatstr[i] == 's' || formatstr[i] == '[' || formatstr[i] == 'S' || (formatstr[i] == 'l' && formatstr[i+1] == 's')) && _settings->isEnabled("warning")) // #3490 - field width limits are only necessary for string input if ((formatstr[i] == 's' || formatstr[i] == '[' || formatstr[i] == 'S' || (formatstr[i] == 'l' && formatstr[i+1] == 's')) && _settings->isEnabled("warning")) // #3490 - field width limits are only necessary for string input
invalidScanfError(tok, false); invalidScanfError(tok, false);
else if (formatstr[i] != 'n' && formatstr[i] != 'c' && !windows && _settings->isEnabled("portability")) else if (formatstr[i] != 'n' && formatstr[i] != 'c' && !windows && _settings->isEnabled("portability"))
@ -594,7 +594,7 @@ void CheckIO::checkWrongPrintfScanfArguments()
std::string width; std::string width;
unsigned int parameterPosition = 0; unsigned int parameterPosition = 0;
bool hasParameterPosition = false; bool hasParameterPosition = false;
while (i != formatString.end() && *i != '[' && !std::isalpha(*i)) { while (i != formatString.end() && *i != '[' && !std::isalpha((unsigned char)*i)) {
if (*i == '*') { if (*i == '*') {
skip = true; skip = true;
if (scan) if (scan)

View File

@ -278,7 +278,7 @@ void CheckNullPointer::parseFunctionCall(const Token &tok, std::list<const Token
percent = false; percent = false;
bool _continue = false; bool _continue = false;
while (!std::isalpha(*i)) { while (!std::isalpha((unsigned char)*i)) {
if (*i == '*') { if (*i == '*') {
if (scan) if (scan)
_continue = true; _continue = true;

View File

@ -1391,7 +1391,7 @@ bool CheckUninitVar::checkScopeForVariable(const Scope* scope, const Token *tok,
const Token *tok2 = forwhile ? tok->next()->link()->next() : tok->next(); const Token *tok2 = forwhile ? tok->next()->link()->next() : tok->next();
if (tok2 && tok2->str() == "{") { if (tok2 && tok2->str() == "{") {
bool init = checkLoopBody(tok2, var, alloc && *alloc, membervar, (number_of_if > 0) | suppressErrors); bool init = checkLoopBody(tok2, var, alloc && *alloc, membervar, (number_of_if > 0) || suppressErrors);
// variable is initialized in the loop.. // variable is initialized in the loop..
if (init) if (init)

View File

@ -398,7 +398,7 @@ std::string Preprocessor::preprocessCleanupDirectives(const std::string &process
if (needSpace) { if (needSpace) {
if (*i == '(' || *i == '!') if (*i == '(' || *i == '!')
code << " "; code << " ";
else if (!std::isalpha(*i)) else if (!std::isalpha((unsigned char)*i))
needSpace = false; needSpace = false;
} }
if (*i == '#') if (*i == '#')
@ -583,10 +583,10 @@ std::string Preprocessor::removeComments(const std::string &str, const std::stri
suppressionIDs.push_back(word); suppressionIDs.push_back(word);
} }
} }
} else if ((i==0 || std::isspace(str[i-1])) && str.compare(i,5,"__asm") == 0) { } else if ((i == 0 || std::isspace((unsigned char)str[i-1])) && str.compare(i, 5, "__asm") == 0) {
while (i < str.size() && (std::isalpha(str[i]) || str[i]=='_')) while (i < str.size() && (std::isalpha((unsigned char)str[i]) || str[i] == '_'))
code << str[i++]; code << str[i++];
while (i < str.size() && std::isspace(str[i])) while (i < str.size() && std::isspace((unsigned char)str[i]))
code << str[i++]; code << str[i++];
if (str[i] == '{') { if (str[i] == '{') {
// Ticket 4873: Extract comments from the __asm / __asm__'s content // Ticket 4873: Extract comments from the __asm / __asm__'s content
@ -1345,9 +1345,9 @@ std::list<std::string> Preprocessor::getcfgs(const std::string &filedata, const
// Check if condition match pattern "%var% == %num%" // Check if condition match pattern "%var% == %num%"
// %var% // %var%
std::string::size_type pos = 0; std::string::size_type pos = 0;
if (std::isalpha(def[pos]) || def[pos] == '_') { if (std::isalpha((unsigned char)def[pos]) || def[pos] == '_') {
++pos; ++pos;
while (std::isalnum(def[pos]) || def[pos] == '_') while (std::isalnum((unsigned char)def[pos]) || def[pos] == '_')
++pos; ++pos;
} }
@ -1361,10 +1361,10 @@ std::list<std::string> Preprocessor::getcfgs(const std::string &filedata, const
pos += 2; pos += 2;
if (pos >= def.size()) if (pos >= def.size())
pos = 0; pos = 0;
while (pos < def.size() && std::isxdigit(def[pos])) while (pos < def.size() && std::isxdigit((unsigned char)def[pos]))
++pos; ++pos;
} else { } else {
while (pos < def.size() && std::isdigit(def[pos])) while (pos < def.size() && std::isdigit((unsigned char)def[pos]))
++pos; ++pos;
} }
@ -1558,11 +1558,11 @@ std::list<std::string> Preprocessor::getcfgs(const std::string &filedata, const
// identifier.. // identifier..
if (std::isalpha(c) || c == '_') { if (std::isalpha(c) || c == '_') {
while (std::isalnum(s[pos]) || s[pos] == '_') while (std::isalnum((unsigned char)s[pos]) || s[pos] == '_')
++pos; ++pos;
if (s[pos] == '=') { if (s[pos] == '=') {
++pos; ++pos;
while (std::isdigit(s[pos])) while (std::isdigit((unsigned char)s[pos]))
++pos; ++pos;
if (s[pos] != ';') { if (s[pos] != ';') {
unhandled = true; unhandled = true;
@ -2492,7 +2492,7 @@ static void getparams(const std::string &line,
// spaces are only added if needed // spaces are only added if needed
else if (line[pos] == ' ') { else if (line[pos] == ' ') {
// Add space only if it is needed // Add space only if it is needed
if (par.size() && std::isalnum(par[par.length()-1])) { if (par.size() && std::isalnum((unsigned char)par[par.length()-1])) {
par += ' '; par += ' ';
} }
} }
@ -2894,9 +2894,9 @@ bool Preprocessor::validateCfg(const std::string &code, const std::string &cfg)
// is macro used in code? // is macro used in code?
else if (code.compare(pos1,macro.size(),macro) == 0) { else if (code.compare(pos1,macro.size(),macro) == 0) {
if (pos1 > 0 && (std::isalnum(code[pos1-1U]) || code[pos1-1U] == '_')) if (pos1 > 0 && (std::isalnum((unsigned char)code[pos1-1U]) || code[pos1-1U] == '_'))
continue; continue;
if (pos2 < code.size() && (std::isalnum(code[pos2]) || code[pos2] == '_')) if (pos2 < code.size() && (std::isalnum((unsigned char)code[pos2]) || code[pos2] == '_'))
continue; continue;
// macro is used in code, return false // macro is used in code, return false
if (_settings->isEnabled("information")) if (_settings->isEnabled("information"))
@ -3059,17 +3059,17 @@ std::string Preprocessor::expandMacros(const std::string &code, std::string file
continue; continue;
} }
if (!std::isalpha(line[pos]) && line[pos] != '_') if (!std::isalpha((unsigned char)line[pos]) && line[pos] != '_')
++pos; ++pos;
// found an identifier.. // found an identifier..
// the "while" is used in case the expanded macro will immediately call another macro // the "while" is used in case the expanded macro will immediately call another macro
while (pos < line.length() && (std::isalpha(line[pos]) || line[pos] == '_')) { while (pos < line.length() && (std::isalpha((unsigned char)line[pos]) || line[pos] == '_')) {
// pos1 = start position of macro // pos1 = start position of macro
const std::string::size_type pos1 = pos++; const std::string::size_type pos1 = pos++;
// find the end of the identifier // find the end of the identifier
while (pos < line.size() && (std::isalnum(line[pos]) || line[pos] == '_')) while (pos < line.size() && (std::isalnum((unsigned char)line[pos]) || line[pos] == '_'))
++pos; ++pos;
// get identifier // get identifier
@ -3162,7 +3162,7 @@ std::string Preprocessor::expandMacros(const std::string &code, std::string file
line.erase(pos1, pos2 - pos1); line.erase(pos1, pos2 - pos1);
// Don't glue this macro into variable or number after it // Don't glue this macro into variable or number after it
if (!line.empty() && (std::isalnum(line[pos1]) || line[pos1] == '_')) if (!line.empty() && (std::isalnum((unsigned char)line[pos1]) || line[pos1] == '_'))
macrocode.append(1,' '); macrocode.append(1,' ');
// insert macrochar before each symbol/nr/operator // insert macrochar before each symbol/nr/operator
@ -3179,14 +3179,14 @@ std::string Preprocessor::expandMacros(const std::string &code, std::string file
else if (str || chr) else if (str || chr)
continue; continue;
else if (macrocode[i] == '.') { // 5. / .5 else if (macrocode[i] == '.') { // 5. / .5
if ((i > 0U && std::isdigit(macrocode[i-1])) || if ((i > 0U && std::isdigit((unsigned char)macrocode[i-1])) ||
(i+1 < macrocode.size() && std::isdigit(macrocode[i+1]))) { (i+1 < macrocode.size() && std::isdigit((unsigned char)macrocode[i+1]))) {
if (i > 0U && !std::isdigit(macrocode[i-1])) { if (i > 0U && !std::isdigit((unsigned char)macrocode[i-1])) {
macrocode.insert(i, 1U, macroChar); macrocode.insert(i, 1U, macroChar);
i++; i++;
} }
i++; i++;
if (i<macrocode.size() && std::isdigit(macrocode[i])) if (i<macrocode.size() && std::isdigit((unsigned char)macrocode[i]))
i++; i++;
if (i+1U < macrocode.size() && if (i+1U < macrocode.size() &&
(macrocode[i] == 'e' || macrocode[i] == 'E') && (macrocode[i] == 'e' || macrocode[i] == 'E') &&
@ -3194,9 +3194,9 @@ std::string Preprocessor::expandMacros(const std::string &code, std::string file
i+=2; i+=2;
} }
} }
} else if (std::isalnum(macrocode[i]) || macrocode[i] == '_') { } else if (std::isalnum((unsigned char)macrocode[i]) || macrocode[i] == '_') {
if ((i > 0U) && if ((i > 0U) &&
(!std::isalnum(macrocode[i-1])) && (!std::isalnum((unsigned char)macrocode[i-1])) &&
(macrocode[i-1] != '_') && (macrocode[i-1] != '_') &&
(macrocode[i-1] != macroChar)) { (macrocode[i-1] != macroChar)) {
macrocode.insert(i, 1U, macroChar); macrocode.insert(i, 1U, macroChar);
@ -3204,23 +3204,23 @@ std::string Preprocessor::expandMacros(const std::string &code, std::string file
// 1e-7 / 1e+7 // 1e-7 / 1e+7
if (i+3U < macrocode.size() && if (i+3U < macrocode.size() &&
(std::isdigit(macrocode[i]) || macrocode[i]=='.') && (std::isdigit((unsigned char)macrocode[i]) || macrocode[i]=='.') &&
(macrocode[i+1] == 'e' || macrocode[i+1] == 'E') && (macrocode[i+1] == 'e' || macrocode[i+1] == 'E') &&
(macrocode[i+2] == '-' || macrocode[i+2] == '+') && (macrocode[i+2] == '-' || macrocode[i+2] == '+') &&
std::isdigit(macrocode[i+3])) { std::isdigit((unsigned char)macrocode[i+3])) {
i += 3U; i += 3U;
} }
// 1.f / 1.e7 // 1.f / 1.e7
if (i+2U < macrocode.size() && if (i+2U < macrocode.size() &&
std::isdigit(macrocode[i]) && std::isdigit((unsigned char)macrocode[i]) &&
macrocode[i+1] == '.' && macrocode[i+1] == '.' &&
std::isalpha(macrocode[i+2])) { std::isalpha((unsigned char)macrocode[i+2])) {
i += 2U; i += 2U;
if (i+2U < macrocode.size() && if (i+2U < macrocode.size() &&
(macrocode[i+0] == 'e' || macrocode[i+0] == 'E') && (macrocode[i+0] == 'e' || macrocode[i+0] == 'E') &&
(macrocode[i+1] == '-' || macrocode[i+1] == '+') && (macrocode[i+1] == '-' || macrocode[i+1] == '+') &&
std::isdigit(macrocode[i+2])) { std::isdigit((unsigned char)macrocode[i+2])) {
i += 2U; i += 2U;
} }
} }

View File

@ -71,12 +71,12 @@ void Token::update_property_info()
if (!_str.empty()) { if (!_str.empty()) {
if (_str == "true" || _str == "false") if (_str == "true" || _str == "false")
_type = eBoolean; _type = eBoolean;
else if (_str[0] == '_' || std::isalpha(_str[0])) { // Name else if (_str[0] == '_' || std::isalpha((unsigned char)_str[0])) { // Name
if (_varId) if (_varId)
_type = eVariable; _type = eVariable;
else if (_type != eVariable && _type != eFunction && _type != eType) else if (_type != eVariable && _type != eFunction && _type != eType)
_type = eName; _type = eName;
} else if (std::isdigit(_str[0]) || (_str.length() > 1 && _str[0] == '-' && std::isdigit(_str[1]))) } else if (std::isdigit(_str[0]) || (_str.length() > 1 && _str[0] == '-' && std::isdigit((unsigned char)_str[1])))
_type = eNumber; _type = eNumber;
else if (_str.length() > 1 && _str[0] == '"' && _str[_str.length()-1] == '"') else if (_str.length() > 1 && _str[0] == '"' && _str[_str.length()-1] == '"')
_type = eString; _type = eString;

View File

@ -8722,7 +8722,7 @@ std::string Tokenizer::simplifyString(const std::string &source)
unsigned int sz = 0; // size of stringdata unsigned int sz = 0; // size of stringdata
if (str[i+1] == 'x') { if (str[i+1] == 'x') {
sz = 2; sz = 2;
while (std::isxdigit(str[i+sz]) && sz < 4) while (std::isxdigit((unsigned char)str[i+sz]) && sz < 4)
sz++; sz++;
if (sz > 2) { if (sz > 2) {
std::istringstream istr(str.substr(i+2, sz-2)); std::istringstream istr(str.substr(i+2, sz-2));