Unsigned division: Checking if negative constant is used
This commit is contained in:
parent
3d14bbea56
commit
b2b3e48ebc
|
@ -349,6 +349,30 @@ void CheckUnsignedDivision()
|
|||
ReportErr(ostr.str());
|
||||
}
|
||||
}
|
||||
|
||||
else if (!Match(tok,"[).]") && Match(tok->next, "%var% / - %num%"))
|
||||
{
|
||||
const char *varname1 = getstr(tok,1);
|
||||
char sign1 = varsign[varname1];
|
||||
if ( sign1 == 'u' )
|
||||
{
|
||||
std::ostringstream ostr;
|
||||
ostr << FileLine(tok->next) << ": Unsigned division. The result will be wrong.";
|
||||
ReportErr(ostr.str());
|
||||
}
|
||||
}
|
||||
|
||||
else if (Match(tok, "[([=*/+-] - %num% / %var%"))
|
||||
{
|
||||
const char *varname2 = getstr(tok,4);
|
||||
char sign2 = varsign[varname2];
|
||||
if ( sign2 == 'u' )
|
||||
{
|
||||
std::ostringstream ostr;
|
||||
ostr << FileLine(tok->next) << ": Unsigned division. The result will be wrong.";
|
||||
ReportErr(ostr.str());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
|
|
@ -111,7 +111,7 @@ public:
|
|||
" unsigned int val = 32;\n"
|
||||
" int i = val / -2;\n"
|
||||
);
|
||||
ASSERT_EQUALS( std::string("[test.cpp:4]: The division result will be wrong\n"), errout.str() );
|
||||
ASSERT_EQUALS( std::string("[test.cpp:4]: Unsigned division. The result will be wrong.\n"), errout.str() );
|
||||
}
|
||||
|
||||
void division7()
|
||||
|
@ -121,7 +121,7 @@ public:
|
|||
" unsigned int val = 32;\n"
|
||||
" int i = -96 / val;\n"
|
||||
);
|
||||
ASSERT_EQUALS( std::string("[test.cpp:4]: The division result will be wrong\n"), errout.str() );
|
||||
ASSERT_EQUALS( std::string("[test.cpp:4]: Unsigned division. The result will be wrong.\n"), errout.str() );
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue