From e26c9990205276d2c0f5d7f0604bc3328ac02ffe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 2 May 2009 10:45:15 +0200 Subject: [PATCH] Refactoring: Using MathLib for converting string to number MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit commit beacd5793f9e9987432a20ac39a76ae6c2c8babd Author: Daniel Marjamäki Date: Sat May 2 10:44:18 2009 +0200 memleak: using mathlib commit 4d28172a5d88cc2cbe5ed94a4e4fdbd0dd4bb5e1 Author: Daniel Marjamäki Date: Sat May 2 10:35:06 2009 +0200 tokenizer: using the MathLib for converting string to number commit 4e4b95b3554c9c6d121efeb39741204b1621b1a3 Author: Daniel Marjamäki Date: Sat May 2 10:28:39 2009 +0200 CheckOther: Using mathlib --- src/checkmemoryleak.cpp | 4 ++-- src/checkother.cpp | 4 ++-- src/mathlib.h | 4 ++-- src/tokenize.cpp | 3 +-- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/checkmemoryleak.cpp b/src/checkmemoryleak.cpp index 01c931f50..d51ddfe62 100644 --- a/src/checkmemoryleak.cpp +++ b/src/checkmemoryleak.cpp @@ -19,7 +19,7 @@ #include "checkmemoryleak.h" - +#include "mathlib.h" #include "tokenize.h" #include @@ -398,7 +398,7 @@ Token *CheckMemoryLeakClass::getcode(const Token *tok, std::list if (sz > 1 && Token::Match(tok->tokAt(2), "malloc ( %num% )") && - (std::atoi(tok->strAt(4)) % sz) != 0) + (MathLib::toLongNumber(tok->strAt(4)) % sz) != 0) { mismatchSizeError(tok->tokAt(4), tok->strAt(4)); } diff --git a/src/checkother.cpp b/src/checkother.cpp index 52efea464..40abe1453 100644 --- a/src/checkother.cpp +++ b/src/checkother.cpp @@ -20,13 +20,13 @@ //--------------------------------------------------------------------------- #include "checkother.h" +#include "mathlib.h" #include "tokenize.h" #include #include #include #include -#include // <- atoi #include #include //--------------------------------------------------------------------------- @@ -328,7 +328,7 @@ void CheckOther::InvalidFunctionUsage() { if (Token::Match(tok2, ", %num% )")) { - int radix = std::atoi(tok2->strAt(1)); + int radix = MathLib::toLongNumber(tok2->next()->str()); if (!(radix == 0 || (radix >= 2 && radix <= 36))) { dangerousUsageStrtolError(tok2); diff --git a/src/mathlib.h b/src/mathlib.h index d4e9fff13..36d8b8108 100644 --- a/src/mathlib.h +++ b/src/mathlib.h @@ -25,7 +25,7 @@ class MathLib { -private: +public: static long toLongNumber(const std::string & str); static double toDoubleNumber(const std::string & str); @@ -33,7 +33,7 @@ private: static std::string toString(T d); static bool isInt(const std::string & str); -public: + static std::string add(const std::string & first, const std::string & second); static std::string subtract(const std::string & first, const std::string & second); static std::string multiply(const std::string & first, const std::string & second); diff --git a/src/tokenize.cpp b/src/tokenize.cpp index d8fe194fc..a91b3d7ae 100644 --- a/src/tokenize.cpp +++ b/src/tokenize.cpp @@ -31,7 +31,6 @@ #include #include #include -#include #include //--------------------------------------------------------------------------- @@ -1085,7 +1084,7 @@ void Tokenizer::simplifyTokenList() if (varid == 0) continue; - int total_size = size * std::atoi(tok->strAt(3)); + int total_size = size * MathLib::toLongNumber(tok->strAt(3)); // Replace 'sizeof(var)' with number int indentlevel = 0;