From 0597026f1342afe540573c0abdb4cd7a4f26c3d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 9 Mar 2010 11:03:45 +0100 Subject: [PATCH] Revert "checkbufferoverrun: Fixed signedness compiler warnings" This reverts commit 3123de346cd959244315a687c7c8adc89ae46488. This commit caused failed tests --- lib/checkbufferoverrun.cpp | 41 ++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/lib/checkbufferoverrun.cpp b/lib/checkbufferoverrun.cpp index 92241ef1f..b0aaafbfa 100644 --- a/lib/checkbufferoverrun.cpp +++ b/lib/checkbufferoverrun.cpp @@ -182,8 +182,11 @@ void CheckBufferOverrun::checkScope(const Token *tok, const std::vectornext(); @@ -594,8 +597,8 @@ void CheckBufferOverrun::checkScope(const Token *tok, const std::vectorstrAt(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(total_size)) { bufferOverrun(tok); continue; @@ -607,8 +610,8 @@ void CheckBufferOverrun::checkScope(const Token *tok, const std::vectorstrAt(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(total_size)) { bufferOverrun(tok); continue; @@ -618,8 +621,8 @@ void CheckBufferOverrun::checkScope(const Token *tok, const std::vector 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 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_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(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') {