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:
parent
6f4c5ab71c
commit
e26c999020
|
@ -19,7 +19,7 @@
|
||||||
|
|
||||||
|
|
||||||
#include "checkmemoryleak.h"
|
#include "checkmemoryleak.h"
|
||||||
|
#include "mathlib.h"
|
||||||
#include "tokenize.h"
|
#include "tokenize.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
@ -398,7 +398,7 @@ Token *CheckMemoryLeakClass::getcode(const Token *tok, std::list<const Token *>
|
||||||
|
|
||||||
if (sz > 1 &&
|
if (sz > 1 &&
|
||||||
Token::Match(tok->tokAt(2), "malloc ( %num% )") &&
|
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));
|
mismatchSizeError(tok->tokAt(4), tok->strAt(4));
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,13 +20,13 @@
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
#include "checkother.h"
|
#include "checkother.h"
|
||||||
|
#include "mathlib.h"
|
||||||
#include "tokenize.h"
|
#include "tokenize.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <cstdlib> // <- atoi
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
@ -328,7 +328,7 @@ void CheckOther::InvalidFunctionUsage()
|
||||||
{
|
{
|
||||||
if (Token::Match(tok2, ", %num% )"))
|
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)))
|
if (!(radix == 0 || (radix >= 2 && radix <= 36)))
|
||||||
{
|
{
|
||||||
dangerousUsageStrtolError(tok2);
|
dangerousUsageStrtolError(tok2);
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
|
|
||||||
class MathLib
|
class MathLib
|
||||||
{
|
{
|
||||||
private:
|
public:
|
||||||
static long toLongNumber(const std::string & str);
|
static long toLongNumber(const std::string & str);
|
||||||
static double toDoubleNumber(const std::string & str);
|
static double toDoubleNumber(const std::string & str);
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ private:
|
||||||
static std::string toString(T d);
|
static std::string toString(T d);
|
||||||
|
|
||||||
static bool isInt(const std::string & str);
|
static bool isInt(const std::string & str);
|
||||||
public:
|
|
||||||
static std::string add(const std::string & first, const std::string & second);
|
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 subtract(const std::string & first, const std::string & second);
|
||||||
static std::string multiply(const std::string & first, const std::string & second);
|
static std::string multiply(const std::string & first, const std::string & second);
|
||||||
|
|
|
@ -31,7 +31,6 @@
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cstdlib>
|
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
@ -1085,7 +1084,7 @@ void Tokenizer::simplifyTokenList()
|
||||||
if (varid == 0)
|
if (varid == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
int total_size = size * std::atoi(tok->strAt(3));
|
int total_size = size * MathLib::toLongNumber(tok->strAt(3));
|
||||||
|
|
||||||
// Replace 'sizeof(var)' with number
|
// Replace 'sizeof(var)' with number
|
||||||
int indentlevel = 0;
|
int indentlevel = 0;
|
||||||
|
|
Loading…
Reference in New Issue