From 3de825c2902935c0b90c647fc65a4186eb3f6fbc Mon Sep 17 00:00:00 2001 From: danmar Date: Thu, 13 Aug 2009 22:13:52 +0200 Subject: [PATCH] Borland C++ Builder: Fixed compilation and testrunner problems --- src/checkbufferoverrun.cpp | 14 +-- src/mathlib.cpp | 24 +++-- src/token.cpp | 4 +- test/testmemleak.cpp | 1 + testrunner.cbproj | 193 +++++++++++++++++++++---------------- 5 files changed, 137 insertions(+), 99 deletions(-) diff --git a/src/checkbufferoverrun.cpp b/src/checkbufferoverrun.cpp index 946c79cfe..35e88bd0d 100644 --- a/src/checkbufferoverrun.cpp +++ b/src/checkbufferoverrun.cpp @@ -252,7 +252,7 @@ void CheckBufferOverrun::checkScope(const Token *tok, const char *varname[], con { if (Token::Match(tok2, "%varid% < %num% ;", counter_varid)) { - max_counter_value = MathLib::toString(atol(tok2->strAt(2)) - 1); + max_counter_value = MathLib::toString(std::atol(tok2->strAt(2)) - 1); } else if (Token::Match(tok2, "%varid% <= %num% ;", counter_varid)) { @@ -318,8 +318,8 @@ void CheckBufferOverrun::checkScope(const Token *tok, const char *varname[], con //printf("min_index: %s %c %s\n", min_counter_value.c_str(), action, second.c_str()); //printf("max_index: %s %c %s\n", max_counter_value.c_str(), action, second.c_str()); - min_index = atoi(MathLib::calculate(min_counter_value, second, action).c_str()); - max_index = atoi(MathLib::calculate(max_counter_value, second, action).c_str()); + min_index = std::atoi(MathLib::calculate(min_counter_value, second, action).c_str()); + max_index = std::atoi(MathLib::calculate(max_counter_value, second, action).c_str()); } else if (Token::Match(tok2, "%varid% [ %num% +|-|*|/ %var% ]", varid) && tok2->tokAt(4)->varId() == counter_varid) @@ -330,8 +330,8 @@ void CheckBufferOverrun::checkScope(const Token *tok, const char *varname[], con //printf("min_index: %s %c %s\n", first.c_str(), action, min_counter_value.c_str()); //printf("max_index: %s %c %s\n", first.c_str(), action, max_counter_value.c_str()); - min_index = atoi(MathLib::calculate(first, min_counter_value, action).c_str()); - max_index = atoi(MathLib::calculate(first, max_counter_value, action).c_str()); + min_index = std::atoi(MathLib::calculate(first, min_counter_value, action).c_str()); + max_index = std::atoi(MathLib::calculate(first, max_counter_value, action).c_str()); } //printf("min_index = %d, max_index = %d, size = %d\n", min_index, max_index, size); @@ -369,7 +369,7 @@ void CheckBufferOverrun::checkScope(const Token *tok, const char *varname[], con // Dangerous usage of strncat.. if (varid > 0 && Token::Match(tok, "strncat ( %varid% , %any% , %num% )", varid)) { - int n = atoi(tok->strAt(6)); + int n = std::atoi(tok->strAt(6)); if (n >= (size - 1)) strncatUsage(tok); } @@ -378,7 +378,7 @@ void CheckBufferOverrun::checkScope(const Token *tok, const char *varname[], con // Dangerous usage of strncpy + strncat.. if (varid > 0 && Token::Match(tok, "strncpy|strncat ( %varid% , %any% , %num% ) ; strncat ( %varid% , %any% , %num% )", varid)) { - int n = atoi(tok->strAt(6)) + atoi(tok->strAt(15)); + int n = std::atoi(tok->strAt(6)) + std::atoi(tok->strAt(15)); if (n > size) strncatUsage(tok->tokAt(9)); } diff --git a/src/mathlib.cpp b/src/mathlib.cpp index 2a61f734e..1b9ca7ae0 100644 --- a/src/mathlib.cpp +++ b/src/mathlib.cpp @@ -33,18 +33,26 @@ long MathLib::toLongNumber(const std::string &str) { if (strncmp(str.c_str(), "0x", 2) == 0) { - return strtoul(str.c_str(), '\0', 16); + return std::strtoul(str.c_str(), '\0', 16); } if (strncmp(str.c_str(), "0", 1) == 0) { - return strtoul(str.c_str(), '\0', 8); + return std::strtoul(str.c_str(), '\0', 8); } - return atol(str.c_str()); + return std::atol(str.c_str()); } double MathLib::toDoubleNumber(const std::string &str) { - return atof(str.c_str()); + if (strncmp(str.c_str(), "0x", 2) == 0) + { + return std::strtoul(str.c_str(), '\0', 16); + } + if (strncmp(str.c_str(), "0", 1) == 0) + { + return std::strtoul(str.c_str(), '\0', 8); + } + return std::atof(str.c_str()); } template @@ -137,24 +145,24 @@ std::string MathLib::calculate(const std::string &first, const std::string &seco std::string MathLib::sin(const std::string &tok) { - return toString(::sin(toDoubleNumber(tok))); + return toString(std::sin(toDoubleNumber(tok))); } std::string MathLib::cos(const std::string &tok) { - return toString(::cos(toDoubleNumber(tok))); + return toString(std::cos(toDoubleNumber(tok))); } std::string MathLib::tan(const std::string &tok) { - return toString(::tan(toDoubleNumber(tok))); + return toString(std::tan(toDoubleNumber(tok))); } std::string MathLib::abs(const std::string &tok) { - return toString(::abs(toDoubleNumber(tok))); + return toString(std::abs(toDoubleNumber(tok))); } bool MathLib::isGreater(const std::string &first, const std::string &second) diff --git a/src/token.cpp b/src/token.cpp index f7dea2b28..480781d56 100644 --- a/src/token.cpp +++ b/src/token.cpp @@ -131,7 +131,7 @@ void Token::replace(Token *replaceThis, Token *start, Token *end) const Token *Token::tokAt(int index) const { const Token *tok = this; - int num = abs(index); + int num = std::abs(index); while (num > 0 && tok) { if (index > 0) @@ -146,7 +146,7 @@ const Token *Token::tokAt(int index) const Token *Token::tokAt(int index) { Token *tok = this; - int num = abs(index); + int num = std::abs(index); while (num > 0 && tok) { if (index > 0) diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index ba9078e59..cdbefffcc 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -1709,6 +1709,7 @@ private: CheckMemoryLeakInFunction checkMemoryLeak; std::list callstack; CheckMemoryLeak::AllocType allocType, deallocType; + allocType = deallocType = CheckMemoryLeak::No; bool all = false; Token *tokens = checkMemoryLeak.getcode(tokenizer.tokens(), callstack, varname, allocType, deallocType, false, all, 1); diff --git a/testrunner.cbproj b/testrunner.cbproj index 5fc9a2d13..0f4c563c3 100644 --- a/testrunner.cbproj +++ b/testrunner.cbproj @@ -18,15 +18,15 @@ Base - true exe - NO_STRICT + true JPHNE + NO_STRICT true - true C:\cppcheck;test;src - CppConsoleApplication + true true + CppConsoleApplication . vclx.bpi;vcl.bpi;rtl.bpi;vclactnband.bpi false @@ -34,10 +34,10 @@ $(BDS)\lib;$(BDS)\lib\obj;$(BDS)\lib\psdk;C:\cppcheck;test;src - false false - _DEBUG;$(Defines) + false true + _DEBUG;$(Defines) true false true @@ -48,8 +48,8 @@ bcb_Debug true true - $(BDS)\lib\debug;$(ILINK_LibraryPath) true + $(BDS)\lib\debug;$(ILINK_LibraryPath) Full true @@ -68,125 +68,154 @@ + + + + TurboPower Async Professional 4.07 Designtime Package - VCL110 Dream Editor Package FalseTrueTrue1$(BDS)\include;$(BDS)\include\dinkumware;$(BDS)\include\vcl;C:\cppcheck2bcb_debug.1$(BDS)\lib\debug;$(BDS)\lib;$(BDS)\lib\obj;$(BDS)\lib\psdk;C:\cppcheck1_DEBUG;NO_STRICT1bcb_Debug + + src\checkautovariables.h + 0 + src\checkbufferoverrun.h - 20 + 1 src\checkclass.h - 21 + 2 - - src\checkfunctionusage.h - 22 + + src\checkdangerousfunctions.h + 3 src\checkheaders.h - 23 + 4 src\checkmemoryleak.h - 24 + 5 src\checkother.h - 25 + 6 + + + src\checkstl.h + 7 + + + src\checkunusedfunctions.h + 8 - 26 + 9 - 27 + 10 - - src\errormessage.h - 28 + + src\errorlogger.h + 11 src\filelister.h - 29 + 12 + + + src\mathlib.h + 13 src\preprocessor.h - 30 + 14 - 31 + 15 + + + 16 src\token.h - 32 + 17 src\tokenize.h - 33 - - - 0 - - - 1 - - - 2 - - - 3 - - - 4 - - - 5 - - - 6 - - - 7 - - - 8 - - - 9 - - - 10 - - - 11 - - - 12 - - - 13 - - - 14 - - - 15 - - - 16 - - - 17 - - 18 - + 19 + + 20 + + + 21 + + + 22 + + + 23 + + + 24 + + + 25 + + + 26 + + + 27 + + + 28 + + + 29 + + + 30 + + + 31 + + + 32 + + + 33 + + + 34 + + + 35 + + + 36 + + + 37 + + + 38 + + + 39 + + + 40 + Cfg_1