Fix #1385 (False positive: unsigned division)
http://sourceforge.net/apps/trac/cppcheck/ticket/1385 This also fixes a bug in setVarId(). "unsigned int a" didn't get varid, untill later when unsigned was simplified away.
This commit is contained in:
parent
669fe1b23d
commit
b52fa9451f
|
@ -323,7 +323,10 @@ void CheckOther::checkUnsignedDivision()
|
||||||
else if (Token::Match(tok, "[{};(,] unsigned %type% %var% [;=,)]"))
|
else if (Token::Match(tok, "[{};(,] unsigned %type% %var% [;=,)]"))
|
||||||
varsign[tok->tokAt(3)->varId()] = 'u';
|
varsign[tok->tokAt(3)->varId()] = 'u';
|
||||||
|
|
||||||
else if (!Token::Match(tok, "[).]") && Token::Match(tok->next(), "%var% / %var%"))
|
else if (!Token::Match(tok, "[).]") &&
|
||||||
|
Token::Match(tok->next(), "%var% / %var%") &&
|
||||||
|
tok->tokAt(1)->varId() != 0 &&
|
||||||
|
tok->tokAt(3)->varId() != 0)
|
||||||
{
|
{
|
||||||
if (ErrorLogger::udivWarning(*_settings))
|
if (ErrorLogger::udivWarning(*_settings))
|
||||||
{
|
{
|
||||||
|
|
|
@ -1830,9 +1830,12 @@ void Tokenizer::setVarId()
|
||||||
if (Token::Match(tok, "[,;{}(] %type%"))
|
if (Token::Match(tok, "[,;{}(] %type%"))
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
|
|
||||||
if (tok->str() == "new" || tok->str() == "unsigned")
|
if (tok->str() == "new")
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
if (tok->str() == "unsigned")
|
||||||
|
tok = tok->next();
|
||||||
|
|
||||||
if (Token::Match(tok, "class|struct %type% :|{|;"))
|
if (Token::Match(tok, "class|struct %type% :|{|;"))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|
|
@ -115,6 +115,17 @@ private:
|
||||||
" result = i2 / i1;}\n"
|
" result = i2 / i1;}\n"
|
||||||
);
|
);
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
check("void f1()\n"
|
||||||
|
"{\n"
|
||||||
|
" unsigned int num = 0;\n"
|
||||||
|
"}\n"
|
||||||
|
"\n"
|
||||||
|
"void f2(int X)\n"
|
||||||
|
"{\n"
|
||||||
|
" X = X / z;}\n"
|
||||||
|
);
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void division5()
|
void division5()
|
||||||
|
|
Loading…
Reference in New Issue