diff --git a/lib/mathlib.cpp b/lib/mathlib.cpp index 9ef2b2af1..8028452c8 100644 --- a/lib/mathlib.cpp +++ b/lib/mathlib.cpp @@ -421,7 +421,7 @@ bool MathLib::isDecimalFloat(const std::string &s) state=BASE_PLUSMINUS; else if (*it=='.') state=LEADING_DECIMAL; - else if (std::isdigit(*it)) + else if (std::isdigit(static_cast(*it))) state=BASE_DIGITS1; else return false; @@ -429,7 +429,7 @@ bool MathLib::isDecimalFloat(const std::string &s) case BASE_PLUSMINUS: if (*it=='.') state=LEADING_DECIMAL; - else if (std::isdigit(*it)) + else if (std::isdigit(static_cast(*it))) state=BASE_DIGITS1; else if (*it=='e' || *it=='E') state=E; @@ -437,7 +437,7 @@ bool MathLib::isDecimalFloat(const std::string &s) return false; break; case LEADING_DECIMAL: - if (std::isdigit(*it)) + if (std::isdigit(static_cast(*it))) state=BASE_DIGITS2; else if (*it=='e' || *it=='E') state=E; @@ -449,7 +449,7 @@ bool MathLib::isDecimalFloat(const std::string &s) state=E; else if (*it=='.') state=TRAILING_DECIMAL; - else if (!std::isdigit(*it)) + else if (!std::isdigit(static_cast(*it))) return false; break; case TRAILING_DECIMAL: @@ -459,7 +459,7 @@ bool MathLib::isDecimalFloat(const std::string &s) state=SUFFIX_F; else if (*it=='l' || *it=='L') state=SUFFIX_L; - else if (std::isdigit(*it)) + else if (std::isdigit(static_cast(*it))) state=BASE_DIGITS2; else return false; @@ -471,19 +471,19 @@ bool MathLib::isDecimalFloat(const std::string &s) state=SUFFIX_F; else if (*it=='l' || *it=='L') state=SUFFIX_L; - else if (!std::isdigit(*it)) + else if (!std::isdigit(static_cast(*it))) return false; break; case E: if (*it=='+' || *it=='-') state=MANTISSA_PLUSMINUS; - else if (std::isdigit(*it)) + else if (std::isdigit(static_cast(*it))) state=MANTISSA_DIGITS; else return false; break; case MANTISSA_PLUSMINUS: - if (!std::isdigit(*it)) + if (!std::isdigit(static_cast(*it))) return false; else state=MANTISSA_DIGITS; @@ -493,7 +493,7 @@ bool MathLib::isDecimalFloat(const std::string &s) state=SUFFIX_F; else if (*it=='l' || *it=='L') state=SUFFIX_L; - else if (!std::isdigit(*it)) + else if (!std::isdigit(static_cast(*it))) return false; break; case SUFFIX_F: @@ -550,13 +550,13 @@ bool MathLib::isOct(const std::string& s) return false; break; case OCTAL_PREFIX: - if (isOctalDigit(*it)) + if (isOctalDigit(static_cast(*it))) state = DIGITS; else return false; break; case DIGITS: - if (isOctalDigit(*it)) + if (isOctalDigit(static_cast(*it))) state = DIGITS; else return isValidIntegerSuffix(it,s.end()); @@ -594,13 +594,13 @@ bool MathLib::isIntHex(const std::string& s) return false; break; case DIGIT: - if (isxdigit(*it)) + if (isxdigit(static_cast(*it))) state = DIGITS; else return false; break; case DIGITS: - if (isxdigit(*it)) + if (isxdigit(static_cast(*it))) state = DIGITS; else return isValidIntegerSuffix(it,s.end()); @@ -638,13 +638,13 @@ bool MathLib::isFloatHex(const std::string& s) return false; break; case WHOLE_NUMBER_DIGIT: - if (isxdigit(*it)) + if (isxdigit(static_cast(*it))) state = WHOLE_NUMBER_DIGITS; else return false; break; case WHOLE_NUMBER_DIGITS: - if (isxdigit(*it)) + if (isxdigit(static_cast(*it))) state = WHOLE_NUMBER_DIGITS; else if (*it=='.') state = FRACTION; @@ -654,13 +654,13 @@ bool MathLib::isFloatHex(const std::string& s) return false; break; case FRACTION: - if (isxdigit(*it)) + if (isxdigit(static_cast(*it))) state = FRACTION; else if (*it=='p' || *it=='P') state = EXPONENT_DIGIT; break; case EXPONENT_DIGIT: - if (isxdigit(*it)) + if (isxdigit(static_cast(*it))) state = EXPONENT_DIGITS; else if (*it=='+' || *it=='-') state = EXPONENT_DIGITS; @@ -668,7 +668,7 @@ bool MathLib::isFloatHex(const std::string& s) return false; break; case EXPONENT_DIGITS: - if (isxdigit(*it)) + if (isxdigit(static_cast(*it))) state = EXPONENT_DIGITS; else return *it=='f'||*it=='F'||*it=='l'||*it=='L'; @@ -810,19 +810,19 @@ bool MathLib::isDec(const std::string & s) case START: if (*it == '+' || *it == '-') state = PLUSMINUS; - else if (isdigit(*it)) + else if (isdigit(static_cast(*it))) state = DIGIT; else return false; break; case PLUSMINUS: - if (isdigit(*it)) + if (isdigit(static_cast(*it))) state = DIGIT; else return false; break; case DIGIT: - if (isdigit(*it)) + if (isdigit(static_cast(*it))) state = DIGIT; else return isValidIntegerSuffix(it,s.end()); diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 01323d986..1207dc40d 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -9294,8 +9294,11 @@ void Tokenizer::simplifyAsm2() for (Token *tok = list.front(); tok; tok = tok->next()) { if (Token::simpleMatch(tok, "^ {")) { Token * start = tok; - while (start && !Token::Match(start, "[;{}]")) + while (start && !Token::Match(start, "[;{}]")) { + if (start->link() && Token::Match(start, ")|]")) + start = start->link(); start = start->previous(); + } if (start) start = start->next(); const Token *last = tok->next()->link(); diff --git a/test/testgarbage.cpp b/test/testgarbage.cpp index 7c26f0620..c45639272 100644 --- a/test/testgarbage.cpp +++ b/test/testgarbage.cpp @@ -195,6 +195,7 @@ private: TEST_CASE(garbageCode144); // #6865 TEST_CASE(garbageCode145); // #7074 TEST_CASE(garbageCode146); // #7081 + TEST_CASE(garbageCode147); // #7082 TEST_CASE(garbageValueFlow); TEST_CASE(garbageSymbolDatabase); @@ -1151,6 +1152,20 @@ private: "}"), InternalError); } + void garbageCode147() { // #7082 + checkCode("free(3();\n" + "$ vWrongAllocp1) test1() ^ {\n" + " int *p