Fixed crashs on garbage code (#7082)
This commit is contained in:
parent
23e6e5a568
commit
4f565ba90f
|
@ -421,7 +421,7 @@ bool MathLib::isDecimalFloat(const std::string &s)
|
||||||
state=BASE_PLUSMINUS;
|
state=BASE_PLUSMINUS;
|
||||||
else if (*it=='.')
|
else if (*it=='.')
|
||||||
state=LEADING_DECIMAL;
|
state=LEADING_DECIMAL;
|
||||||
else if (std::isdigit(*it))
|
else if (std::isdigit(static_cast<unsigned char>(*it)))
|
||||||
state=BASE_DIGITS1;
|
state=BASE_DIGITS1;
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
|
@ -429,7 +429,7 @@ bool MathLib::isDecimalFloat(const std::string &s)
|
||||||
case BASE_PLUSMINUS:
|
case BASE_PLUSMINUS:
|
||||||
if (*it=='.')
|
if (*it=='.')
|
||||||
state=LEADING_DECIMAL;
|
state=LEADING_DECIMAL;
|
||||||
else if (std::isdigit(*it))
|
else if (std::isdigit(static_cast<unsigned char>(*it)))
|
||||||
state=BASE_DIGITS1;
|
state=BASE_DIGITS1;
|
||||||
else if (*it=='e' || *it=='E')
|
else if (*it=='e' || *it=='E')
|
||||||
state=E;
|
state=E;
|
||||||
|
@ -437,7 +437,7 @@ bool MathLib::isDecimalFloat(const std::string &s)
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
case LEADING_DECIMAL:
|
case LEADING_DECIMAL:
|
||||||
if (std::isdigit(*it))
|
if (std::isdigit(static_cast<unsigned char>(*it)))
|
||||||
state=BASE_DIGITS2;
|
state=BASE_DIGITS2;
|
||||||
else if (*it=='e' || *it=='E')
|
else if (*it=='e' || *it=='E')
|
||||||
state=E;
|
state=E;
|
||||||
|
@ -449,7 +449,7 @@ bool MathLib::isDecimalFloat(const std::string &s)
|
||||||
state=E;
|
state=E;
|
||||||
else if (*it=='.')
|
else if (*it=='.')
|
||||||
state=TRAILING_DECIMAL;
|
state=TRAILING_DECIMAL;
|
||||||
else if (!std::isdigit(*it))
|
else if (!std::isdigit(static_cast<unsigned char>(*it)))
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
case TRAILING_DECIMAL:
|
case TRAILING_DECIMAL:
|
||||||
|
@ -459,7 +459,7 @@ bool MathLib::isDecimalFloat(const std::string &s)
|
||||||
state=SUFFIX_F;
|
state=SUFFIX_F;
|
||||||
else if (*it=='l' || *it=='L')
|
else if (*it=='l' || *it=='L')
|
||||||
state=SUFFIX_L;
|
state=SUFFIX_L;
|
||||||
else if (std::isdigit(*it))
|
else if (std::isdigit(static_cast<unsigned char>(*it)))
|
||||||
state=BASE_DIGITS2;
|
state=BASE_DIGITS2;
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
|
@ -471,19 +471,19 @@ bool MathLib::isDecimalFloat(const std::string &s)
|
||||||
state=SUFFIX_F;
|
state=SUFFIX_F;
|
||||||
else if (*it=='l' || *it=='L')
|
else if (*it=='l' || *it=='L')
|
||||||
state=SUFFIX_L;
|
state=SUFFIX_L;
|
||||||
else if (!std::isdigit(*it))
|
else if (!std::isdigit(static_cast<unsigned char>(*it)))
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
case E:
|
case E:
|
||||||
if (*it=='+' || *it=='-')
|
if (*it=='+' || *it=='-')
|
||||||
state=MANTISSA_PLUSMINUS;
|
state=MANTISSA_PLUSMINUS;
|
||||||
else if (std::isdigit(*it))
|
else if (std::isdigit(static_cast<unsigned char>(*it)))
|
||||||
state=MANTISSA_DIGITS;
|
state=MANTISSA_DIGITS;
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
case MANTISSA_PLUSMINUS:
|
case MANTISSA_PLUSMINUS:
|
||||||
if (!std::isdigit(*it))
|
if (!std::isdigit(static_cast<unsigned char>(*it)))
|
||||||
return false;
|
return false;
|
||||||
else
|
else
|
||||||
state=MANTISSA_DIGITS;
|
state=MANTISSA_DIGITS;
|
||||||
|
@ -493,7 +493,7 @@ bool MathLib::isDecimalFloat(const std::string &s)
|
||||||
state=SUFFIX_F;
|
state=SUFFIX_F;
|
||||||
else if (*it=='l' || *it=='L')
|
else if (*it=='l' || *it=='L')
|
||||||
state=SUFFIX_L;
|
state=SUFFIX_L;
|
||||||
else if (!std::isdigit(*it))
|
else if (!std::isdigit(static_cast<unsigned char>(*it)))
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
case SUFFIX_F:
|
case SUFFIX_F:
|
||||||
|
@ -550,13 +550,13 @@ bool MathLib::isOct(const std::string& s)
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
case OCTAL_PREFIX:
|
case OCTAL_PREFIX:
|
||||||
if (isOctalDigit(*it))
|
if (isOctalDigit(static_cast<unsigned char>(*it)))
|
||||||
state = DIGITS;
|
state = DIGITS;
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
case DIGITS:
|
case DIGITS:
|
||||||
if (isOctalDigit(*it))
|
if (isOctalDigit(static_cast<unsigned char>(*it)))
|
||||||
state = DIGITS;
|
state = DIGITS;
|
||||||
else
|
else
|
||||||
return isValidIntegerSuffix(it,s.end());
|
return isValidIntegerSuffix(it,s.end());
|
||||||
|
@ -594,13 +594,13 @@ bool MathLib::isIntHex(const std::string& s)
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
case DIGIT:
|
case DIGIT:
|
||||||
if (isxdigit(*it))
|
if (isxdigit(static_cast<unsigned char>(*it)))
|
||||||
state = DIGITS;
|
state = DIGITS;
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
case DIGITS:
|
case DIGITS:
|
||||||
if (isxdigit(*it))
|
if (isxdigit(static_cast<unsigned char>(*it)))
|
||||||
state = DIGITS;
|
state = DIGITS;
|
||||||
else
|
else
|
||||||
return isValidIntegerSuffix(it,s.end());
|
return isValidIntegerSuffix(it,s.end());
|
||||||
|
@ -638,13 +638,13 @@ bool MathLib::isFloatHex(const std::string& s)
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
case WHOLE_NUMBER_DIGIT:
|
case WHOLE_NUMBER_DIGIT:
|
||||||
if (isxdigit(*it))
|
if (isxdigit(static_cast<unsigned char>(*it)))
|
||||||
state = WHOLE_NUMBER_DIGITS;
|
state = WHOLE_NUMBER_DIGITS;
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
case WHOLE_NUMBER_DIGITS:
|
case WHOLE_NUMBER_DIGITS:
|
||||||
if (isxdigit(*it))
|
if (isxdigit(static_cast<unsigned char>(*it)))
|
||||||
state = WHOLE_NUMBER_DIGITS;
|
state = WHOLE_NUMBER_DIGITS;
|
||||||
else if (*it=='.')
|
else if (*it=='.')
|
||||||
state = FRACTION;
|
state = FRACTION;
|
||||||
|
@ -654,13 +654,13 @@ bool MathLib::isFloatHex(const std::string& s)
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
case FRACTION:
|
case FRACTION:
|
||||||
if (isxdigit(*it))
|
if (isxdigit(static_cast<unsigned char>(*it)))
|
||||||
state = FRACTION;
|
state = FRACTION;
|
||||||
else if (*it=='p' || *it=='P')
|
else if (*it=='p' || *it=='P')
|
||||||
state = EXPONENT_DIGIT;
|
state = EXPONENT_DIGIT;
|
||||||
break;
|
break;
|
||||||
case EXPONENT_DIGIT:
|
case EXPONENT_DIGIT:
|
||||||
if (isxdigit(*it))
|
if (isxdigit(static_cast<unsigned char>(*it)))
|
||||||
state = EXPONENT_DIGITS;
|
state = EXPONENT_DIGITS;
|
||||||
else if (*it=='+' || *it=='-')
|
else if (*it=='+' || *it=='-')
|
||||||
state = EXPONENT_DIGITS;
|
state = EXPONENT_DIGITS;
|
||||||
|
@ -668,7 +668,7 @@ bool MathLib::isFloatHex(const std::string& s)
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
case EXPONENT_DIGITS:
|
case EXPONENT_DIGITS:
|
||||||
if (isxdigit(*it))
|
if (isxdigit(static_cast<unsigned char>(*it)))
|
||||||
state = EXPONENT_DIGITS;
|
state = EXPONENT_DIGITS;
|
||||||
else
|
else
|
||||||
return *it=='f'||*it=='F'||*it=='l'||*it=='L';
|
return *it=='f'||*it=='F'||*it=='l'||*it=='L';
|
||||||
|
@ -810,19 +810,19 @@ bool MathLib::isDec(const std::string & s)
|
||||||
case START:
|
case START:
|
||||||
if (*it == '+' || *it == '-')
|
if (*it == '+' || *it == '-')
|
||||||
state = PLUSMINUS;
|
state = PLUSMINUS;
|
||||||
else if (isdigit(*it))
|
else if (isdigit(static_cast<unsigned char>(*it)))
|
||||||
state = DIGIT;
|
state = DIGIT;
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
case PLUSMINUS:
|
case PLUSMINUS:
|
||||||
if (isdigit(*it))
|
if (isdigit(static_cast<unsigned char>(*it)))
|
||||||
state = DIGIT;
|
state = DIGIT;
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
case DIGIT:
|
case DIGIT:
|
||||||
if (isdigit(*it))
|
if (isdigit(static_cast<unsigned char>(*it)))
|
||||||
state = DIGIT;
|
state = DIGIT;
|
||||||
else
|
else
|
||||||
return isValidIntegerSuffix(it,s.end());
|
return isValidIntegerSuffix(it,s.end());
|
||||||
|
|
|
@ -9294,8 +9294,11 @@ void Tokenizer::simplifyAsm2()
|
||||||
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
||||||
if (Token::simpleMatch(tok, "^ {")) {
|
if (Token::simpleMatch(tok, "^ {")) {
|
||||||
Token * start = 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();
|
start = start->previous();
|
||||||
|
}
|
||||||
if (start)
|
if (start)
|
||||||
start = start->next();
|
start = start->next();
|
||||||
const Token *last = tok->next()->link();
|
const Token *last = tok->next()->link();
|
||||||
|
|
|
@ -195,6 +195,7 @@ private:
|
||||||
TEST_CASE(garbageCode144); // #6865
|
TEST_CASE(garbageCode144); // #6865
|
||||||
TEST_CASE(garbageCode145); // #7074
|
TEST_CASE(garbageCode145); // #7074
|
||||||
TEST_CASE(garbageCode146); // #7081
|
TEST_CASE(garbageCode146); // #7081
|
||||||
|
TEST_CASE(garbageCode147); // #7082
|
||||||
|
|
||||||
TEST_CASE(garbageValueFlow);
|
TEST_CASE(garbageValueFlow);
|
||||||
TEST_CASE(garbageSymbolDatabase);
|
TEST_CASE(garbageSymbolDatabase);
|
||||||
|
@ -1151,6 +1152,20 @@ private:
|
||||||
"}"), InternalError);
|
"}"), InternalError);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void garbageCode147() { // #7082
|
||||||
|
checkCode("free(3();\n"
|
||||||
|
"$ vWrongAllocp1) test1<int, -!>() ^ {\n"
|
||||||
|
" int *p<ynew int[n];\n"
|
||||||
|
" delete[]p;\n"
|
||||||
|
" int *p1 = (int*)malloc(n*sizeof(int));\n"
|
||||||
|
" free(p1);\n"
|
||||||
|
"}\n"
|
||||||
|
"void est2() {\n"
|
||||||
|
" for (int ui = 0; ui < 1z; ui++)\n"
|
||||||
|
" ;\n"
|
||||||
|
"}");
|
||||||
|
}
|
||||||
|
|
||||||
void garbageValueFlow() {
|
void garbageValueFlow() {
|
||||||
// #6089
|
// #6089
|
||||||
const char* code = "{} int foo(struct, x1, struct x2, x3, int, x5, x6, x7)\n"
|
const char* code = "{} int foo(struct, x1, struct x2, x3, int, x5, x6, x7)\n"
|
||||||
|
|
Loading…
Reference in New Issue