Revert "checkbufferoverrun: Fixed signedness compiler warnings"
This reverts commit 3123de346c
.
This commit caused failed tests
This commit is contained in:
parent
3123de346c
commit
0597026f13
|
@ -182,8 +182,11 @@ void CheckBufferOverrun::checkScope(const Token *tok, const std::vector<std::str
|
|||
for (unsigned int i = 0; i < varname.size(); ++i)
|
||||
varnames += (i == 0 ? "" : " . ") + varname[i];
|
||||
|
||||
const int varc(varname.empty() ? 0 : int(varname.size() - 1) * 2);
|
||||
unsigned int varc = varname.size();
|
||||
if (varc == 0)
|
||||
varc = 1;
|
||||
|
||||
varc = 2 * (varc - 1);
|
||||
if (Token::Match(tok, "return"))
|
||||
{
|
||||
tok = tok->next();
|
||||
|
@ -594,8 +597,8 @@ void CheckBufferOverrun::checkScope(const Token *tok, const std::vector<std::str
|
|||
Token::Match(tok, "read|write ( %any% , %varid% , %num% )", varid) &&
|
||||
MathLib::isInt(tok->strAt(6)))
|
||||
{
|
||||
long len = MathLib::toLongNumber(tok->strAt(6));
|
||||
if (len < 0 || len > total_size)
|
||||
size_t len = MathLib::toLongNumber(tok->strAt(6));
|
||||
if (len > static_cast<size_t>(total_size))
|
||||
{
|
||||
bufferOverrun(tok);
|
||||
continue;
|
||||
|
@ -607,8 +610,8 @@ void CheckBufferOverrun::checkScope(const Token *tok, const std::vector<std::str
|
|||
Token::Match(tok, "fgets ( %varid% , %num% , %any% )", varid) &&
|
||||
MathLib::isInt(tok->strAt(4)))
|
||||
{
|
||||
long len = MathLib::toLongNumber(tok->strAt(4));
|
||||
if (len < 0 || len > total_size)
|
||||
size_t len = MathLib::toLongNumber(tok->strAt(4));
|
||||
if (len > static_cast<size_t>(total_size))
|
||||
{
|
||||
bufferOverrun(tok);
|
||||
continue;
|
||||
|
@ -618,8 +621,8 @@ void CheckBufferOverrun::checkScope(const Token *tok, const std::vector<std::str
|
|||
// Dangerous usage of strncat..
|
||||
if (varid > 0 && Token::Match(tok, "strncat ( %varid% , %any% , %num% )", varid))
|
||||
{
|
||||
long n = MathLib::toLongNumber(tok->strAt(6));
|
||||
if (n < 0 || n >= total_size)
|
||||
int n = MathLib::toLongNumber(tok->strAt(6));
|
||||
if (n >= total_size)
|
||||
strncatUsage(tok);
|
||||
}
|
||||
|
||||
|
@ -627,7 +630,7 @@ void CheckBufferOverrun::checkScope(const Token *tok, const std::vector<std::str
|
|||
// Dangerous usage of strncpy + strncat..
|
||||
if (varid > 0 && Token::Match(tok, "strncpy|strncat ( %varid% , %any% , %num% ) ; strncat ( %varid% , %any% , %num% )", varid))
|
||||
{
|
||||
long n = MathLib::toLongNumber(tok->strAt(6)) + MathLib::toLongNumber(tok->strAt(15));
|
||||
int n = MathLib::toLongNumber(tok->strAt(6)) + MathLib::toLongNumber(tok->strAt(15));
|
||||
if (n > total_size)
|
||||
strncatUsage(tok->tokAt(9));
|
||||
}
|
||||
|
@ -790,7 +793,7 @@ void CheckBufferOverrun::checkGlobalAndLocalVariable()
|
|||
else if (tok->str() == "}")
|
||||
--indentlevel;
|
||||
|
||||
long size = 0;
|
||||
unsigned int size = 0;
|
||||
std::string type;
|
||||
unsigned int varid = 0;
|
||||
int nextTok = 0;
|
||||
|
@ -801,7 +804,7 @@ void CheckBufferOverrun::checkGlobalAndLocalVariable()
|
|||
|
||||
if (Token::Match(tok, "%type% *| %var% [ %num% ] [;=]"))
|
||||
{
|
||||
int varpos = 1;
|
||||
unsigned int varpos = 1;
|
||||
if (tok->next()->str() == "*")
|
||||
++varpos;
|
||||
size = MathLib::toLongNumber(tok->strAt(varpos + 2));
|
||||
|
@ -838,7 +841,7 @@ void CheckBufferOverrun::checkGlobalAndLocalVariable()
|
|||
// malloc() gets count of bytes and not count of
|
||||
// elements, so we should calculate count of elements
|
||||
// manually
|
||||
int sizeOfType = (int)_tokenizer->sizeOfType(declTok);
|
||||
unsigned int sizeOfType = _tokenizer->sizeOfType(declTok);
|
||||
if (sizeOfType > 0)
|
||||
size /= sizeOfType;
|
||||
}
|
||||
|
@ -853,7 +856,7 @@ void CheckBufferOverrun::checkGlobalAndLocalVariable()
|
|||
|
||||
Token sizeTok(0);
|
||||
sizeTok.str(type);
|
||||
int total_size = size * (int)_tokenizer->sizeOfType(&sizeTok);
|
||||
int total_size = size * _tokenizer->sizeOfType(&sizeTok);
|
||||
if (total_size == 0)
|
||||
continue;
|
||||
|
||||
|
@ -900,9 +903,9 @@ void CheckBufferOverrun::checkStructVariable()
|
|||
const unsigned int varId = tok2->tokAt(ivar)->varId();
|
||||
varname[1] = tok2->strAt(ivar);
|
||||
int arrsize = MathLib::toLongNumber(tok2->strAt(ivar + 2));
|
||||
int total_size = arrsize * (int)_tokenizer->sizeOfType(tok2->tokAt(1));
|
||||
int total_size = arrsize * _tokenizer->sizeOfType(tok2->tokAt(1));
|
||||
if (tok2->tokAt(2)->str() == "*")
|
||||
total_size = arrsize * (int)_tokenizer->sizeOfType(tok2->tokAt(2));
|
||||
total_size = arrsize * _tokenizer->sizeOfType(tok2->tokAt(2));
|
||||
if (total_size == 0)
|
||||
continue;
|
||||
|
||||
|
@ -1002,7 +1005,7 @@ int CheckBufferOverrun::countSprintfLength(const std::string &input_string, cons
|
|||
std::string digits_string = "";
|
||||
bool i_d_x_f_found = false;
|
||||
std::list<const Token*>::const_iterator paramIter = parameters.begin();
|
||||
int parameterLength = 0;
|
||||
unsigned int parameterLength = 0;
|
||||
for (std::string::size_type i = 0; i < input_string.length(); ++i)
|
||||
{
|
||||
if (input_string[i] == '\\')
|
||||
|
@ -1037,13 +1040,13 @@ int CheckBufferOverrun::countSprintfLength(const std::string &input_string, cons
|
|||
case 'd':
|
||||
i_d_x_f_found = true;
|
||||
if (paramIter != parameters.end() && *paramIter && (*paramIter)->str()[0] != '"')
|
||||
parameterLength = (int)(*paramIter)->str().length();
|
||||
parameterLength = (*paramIter)->str().length();
|
||||
|
||||
handleNextParameter = true;
|
||||
break;
|
||||
case 's':
|
||||
if (paramIter != parameters.end() && *paramIter && (*paramIter)->str()[0] == '"')
|
||||
parameterLength = (int)Token::getStrLength(*paramIter);
|
||||
parameterLength = Token::getStrLength(*paramIter);
|
||||
|
||||
handleNextParameter = true;
|
||||
break;
|
||||
|
@ -1062,14 +1065,14 @@ int CheckBufferOverrun::countSprintfLength(const std::string &input_string, cons
|
|||
|
||||
if (handleNextParameter)
|
||||
{
|
||||
int tempDigits = std::abs(MathLib::toLongNumber(digits_string));
|
||||
unsigned int tempDigits = std::abs(std::atoi(digits_string.c_str()));
|
||||
if (i_d_x_f_found)
|
||||
tempDigits = std::max(static_cast<int>(tempDigits), 1);
|
||||
|
||||
if (digits_string.find('.') != std::string::npos)
|
||||
{
|
||||
const std::string endStr = digits_string.substr(digits_string.find('.') + 1);
|
||||
int maxLen = std::max((int)std::abs(MathLib::toLongNumber(endStr)), 1);
|
||||
unsigned int maxLen = std::max(std::abs(std::atoi(endStr.c_str())), 1);
|
||||
|
||||
if (input_string[i] == 's')
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue