Refactoring: Using MathLib for converting string to number

commit beacd5793f9e9987432a20ac39a76ae6c2c8babd
Author: Daniel Marjamäki <hyd_danmar@users.sourceforge.net>
Date:   Sat May 2 10:44:18 2009 +0200

    memleak: using mathlib

commit 4d28172a5d88cc2cbe5ed94a4e4fdbd0dd4bb5e1
Author: Daniel Marjamäki <hyd_danmar@users.sourceforge.net>
Date:   Sat May 2 10:35:06 2009 +0200

    tokenizer: using the MathLib for converting string to number

commit 4e4b95b3554c9c6d121efeb39741204b1621b1a3
Author: Daniel Marjamäki <hyd_danmar@users.sourceforge.net>
Date:   Sat May 2 10:28:39 2009 +0200

    CheckOther: Using mathlib
This commit is contained in:
Daniel Marjamäki 2009-05-02 10:45:15 +02:00
parent 6f4c5ab71c
commit e26c999020
4 changed files with 7 additions and 8 deletions

View File

@ -19,7 +19,7 @@
#include "checkmemoryleak.h"
#include "mathlib.h"
#include "tokenize.h"
#include <algorithm>
@ -398,7 +398,7 @@ Token *CheckMemoryLeakClass::getcode(const Token *tok, std::list<const Token *>
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));
}

View File

@ -20,13 +20,13 @@
//---------------------------------------------------------------------------
#include "checkother.h"
#include "mathlib.h"
#include "tokenize.h"
#include <algorithm>
#include <list>
#include <map>
#include <sstream>
#include <cstdlib> // <- atoi
#include <cstring>
#include <cctype>
//---------------------------------------------------------------------------
@ -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);

View File

@ -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);

View File

@ -31,7 +31,6 @@
#include <sstream>
#include <list>
#include <algorithm>
#include <cstdlib>
#include <cctype>
//---------------------------------------------------------------------------
@ -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;