Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ $(libcppdir)/symboldatabase.o: lib/symboldatabase.cpp lib/addoninfo.h lib/astuti
$(libcppdir)/addoninfo.o: lib/addoninfo.cpp externals/picojson/picojson.h lib/addoninfo.h lib/config.h lib/json.h lib/path.h lib/standards.h lib/utils.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/addoninfo.cpp

$(libcppdir)/analyzerinfo.o: lib/analyzerinfo.cpp externals/tinyxml2/tinyxml2.h lib/analyzerinfo.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/filesettings.h lib/path.h lib/platform.h lib/standards.h lib/utils.h lib/xml.h
$(libcppdir)/analyzerinfo.o: lib/analyzerinfo.cpp externals/tinyxml2/tinyxml2.h lib/analyzerinfo.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/filesettings.h lib/mathlib.h lib/path.h lib/platform.h lib/standards.h lib/utils.h lib/xml.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/analyzerinfo.cpp

$(libcppdir)/astutils.o: lib/astutils.cpp lib/addoninfo.h lib/astutils.h lib/check.h lib/checkclass.h lib/config.h lib/errortypes.h lib/findtoken.h lib/infer.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/valueflow.h lib/valueptr.h lib/vfvalue.h
Expand Down Expand Up @@ -611,7 +611,7 @@ $(libcppdir)/pathanalysis.o: lib/pathanalysis.cpp lib/astutils.h lib/config.h li
$(libcppdir)/pathmatch.o: lib/pathmatch.cpp lib/config.h lib/path.h lib/pathmatch.h lib/standards.h lib/utils.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/pathmatch.cpp

$(libcppdir)/platform.o: lib/platform.cpp externals/tinyxml2/tinyxml2.h lib/config.h lib/path.h lib/platform.h lib/standards.h lib/xml.h
$(libcppdir)/platform.o: lib/platform.cpp externals/tinyxml2/tinyxml2.h lib/config.h lib/mathlib.h lib/path.h lib/platform.h lib/standards.h lib/xml.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/platform.cpp

$(libcppdir)/preprocessor.o: lib/preprocessor.cpp externals/simplecpp/simplecpp.h lib/addoninfo.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/preprocessor.h lib/settings.h lib/standards.h lib/suppressions.h lib/utils.h
Expand Down Expand Up @@ -668,16 +668,16 @@ cli/cmdlineparser.o: cli/cmdlineparser.cpp cli/cmdlinelogger.h cli/cmdlineparser
cli/cppcheckexecutor.o: cli/cppcheckexecutor.cpp cli/cmdlinelogger.h cli/cmdlineparser.h cli/cppcheckexecutor.h cli/cppcheckexecutorseh.h cli/executor.h cli/processexecutor.h cli/signalhandler.h cli/singleexecutor.h cli/threadexecutor.h externals/picojson/picojson.h lib/addoninfo.h lib/analyzerinfo.h lib/check.h lib/checkersreport.h lib/color.h lib/config.h lib/cppcheck.h lib/errorlogger.h lib/errortypes.h lib/filesettings.h lib/json.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/utils.h
$(CXX) ${INCLUDE_FOR_CLI} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ cli/cppcheckexecutor.cpp

cli/cppcheckexecutorseh.o: cli/cppcheckexecutorseh.cpp cli/cppcheckexecutor.h cli/cppcheckexecutorseh.h lib/config.h lib/filesettings.h lib/path.h lib/platform.h lib/standards.h lib/utils.h
cli/cppcheckexecutorseh.o: cli/cppcheckexecutorseh.cpp cli/cppcheckexecutor.h cli/cppcheckexecutorseh.h lib/config.h lib/filesettings.h lib/mathlib.h lib/path.h lib/platform.h lib/standards.h lib/utils.h
$(CXX) ${INCLUDE_FOR_CLI} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ cli/cppcheckexecutorseh.cpp

cli/executor.o: cli/executor.cpp cli/executor.h lib/addoninfo.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h
$(CXX) ${INCLUDE_FOR_CLI} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ cli/executor.cpp

cli/filelister.o: cli/filelister.cpp cli/filelister.h lib/config.h lib/filesettings.h lib/path.h lib/pathmatch.h lib/platform.h lib/standards.h lib/utils.h
cli/filelister.o: cli/filelister.cpp cli/filelister.h lib/config.h lib/filesettings.h lib/mathlib.h lib/path.h lib/pathmatch.h lib/platform.h lib/standards.h lib/utils.h
$(CXX) ${INCLUDE_FOR_CLI} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ cli/filelister.cpp

cli/main.o: cli/main.cpp cli/cppcheckexecutor.h lib/config.h lib/errortypes.h lib/filesettings.h lib/path.h lib/platform.h lib/standards.h
cli/main.o: cli/main.cpp cli/cppcheckexecutor.h lib/config.h lib/errortypes.h lib/filesettings.h lib/mathlib.h lib/path.h lib/platform.h lib/standards.h
$(CXX) ${INCLUDE_FOR_CLI} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ cli/main.cpp

cli/processexecutor.o: cli/processexecutor.cpp cli/executor.h cli/processexecutor.h lib/addoninfo.h lib/check.h lib/color.h lib/config.h lib/cppcheck.h lib/errorlogger.h lib/errortypes.h lib/filesettings.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/timer.h
Expand Down Expand Up @@ -920,6 +920,6 @@ externals/simplecpp/simplecpp.o: externals/simplecpp/simplecpp.cpp externals/sim
externals/tinyxml2/tinyxml2.o: externals/tinyxml2/tinyxml2.cpp externals/tinyxml2/tinyxml2.h
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -w -c -o $@ externals/tinyxml2/tinyxml2.cpp

tools/dmake/dmake.o: tools/dmake/dmake.cpp cli/filelister.h lib/config.h lib/filesettings.h lib/path.h lib/pathmatch.h lib/platform.h lib/standards.h lib/utils.h
tools/dmake/dmake.o: tools/dmake/dmake.cpp cli/filelister.h lib/config.h lib/filesettings.h lib/mathlib.h lib/path.h lib/pathmatch.h lib/platform.h lib/standards.h lib/utils.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ tools/dmake/dmake.cpp

6 changes: 3 additions & 3 deletions lib/astutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,10 @@ const Token *findNextTokenFromBreak(const Token *breakToken);
bool extractForLoopValues(const Token *forToken,
nonneg int &varid,
bool &knownInitValue,
long long &initValue,
MathLib::bigint &initValue,
bool &partialCond,
long long &stepValue,
long long &lastValue);
MathLib::bigint &stepValue,
MathLib::bigint &lastValue);

bool precedes(const Token * tok1, const Token * tok2);
bool succeeds(const Token* tok1, const Token* tok2);
Expand Down
2 changes: 1 addition & 1 deletion lib/checkbufferoverrun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ static bool getDimensionsEtc(const Token * const arrayToken, const Settings &set
Dimension dim;
dim.known = value->isKnown();
dim.tok = nullptr;
const int typeSize = array->valueType()->typeSize(settings.platform, array->valueType()->pointer > 1);
const MathLib::bigint typeSize = array->valueType()->typeSize(settings.platform, array->valueType()->pointer > 1);
if (typeSize == 0)
return false;
dim.num = value->intvalue / typeSize;
Expand Down
2 changes: 1 addition & 1 deletion lib/checkcondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2037,7 +2037,7 @@ void CheckCondition::checkCompareValueOutOfTypeRange()
}
}

void CheckCondition::compareValueOutOfTypeRangeError(const Token *comparison, const std::string &type, long long value, bool result)
void CheckCondition::compareValueOutOfTypeRangeError(const Token *comparison, const std::string &type, MathLib::bigint value, bool result)
{
reportError(
comparison,
Expand Down
2 changes: 1 addition & 1 deletion lib/checkcondition.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class CPPCHECKLIB CheckCondition : public Check {
void assignmentInCondition(const Token *eq);

void checkCompareValueOutOfTypeRange();
void compareValueOutOfTypeRangeError(const Token *comparison, const std::string &type, long long value, bool result);
void compareValueOutOfTypeRangeError(const Token *comparison, const std::string &type, MathLib::bigint value, bool result);

void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override {
CheckCondition c(nullptr, settings, errorLogger);
Expand Down
4 changes: 2 additions & 2 deletions lib/checkfunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ void CheckFunctions::invalidFunctionUsage()
&& valueType && (valueType->type == ValueType::Type::CHAR || valueType->type == ValueType::Type::WCHAR_T)
&& !isVariablesChanged(variable->declEndToken(), functionToken, 0 /*indirect*/, { variable }, *mSettings)) {
const Token* varTok = variable->declEndToken();
auto count = -1; // Find out explicitly set count, e.g.: char buf[3] = {...}. Variable 'count' is set to 3 then.
MathLib::bigint count = -1; // Find out explicitly set count, e.g.: char buf[3] = {...}. Variable 'count' is set to 3 then.
if (varTok && Token::simpleMatch(varTok->astOperand1(), "["))
{
const Token* const countTok = varTok->astOperand1()->astOperand2();
Expand Down Expand Up @@ -578,7 +578,7 @@ void CheckFunctions::memsetInvalid2ndParam()
}

if (printWarning && secondParamTok->isNumber()) { // Check if the second parameter is a literal and is out of range
const long long int value = MathLib::toBigNumber(secondParamTok->str());
const MathLib::bigint value = MathLib::toBigNumber(secondParamTok->str());
const long long sCharMin = mSettings->platform.signedCharMin();
const long long uCharMax = mSettings->platform.unsignedCharMax();
if (value < sCharMin || value > uCharMax)
Expand Down
4 changes: 2 additions & 2 deletions lib/clangimport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1579,7 +1579,7 @@ static void setValues(const Tokenizer &tokenizer, const SymbolDatabase *symbolDa
if (!scope.definedType)
continue;

int typeSize = 0;
MathLib::bigint typeSize = 0;
for (const Variable &var: scope.varlist) {
const int mul = std::accumulate(var.dimensions().cbegin(), var.dimensions().cend(), 1, [](int v, const Dimension& dim) {
return v * dim.num;
Expand All @@ -1593,7 +1593,7 @@ static void setValues(const Tokenizer &tokenizer, const SymbolDatabase *symbolDa
for (auto *tok = const_cast<Token*>(tokenizer.tokens()); tok; tok = tok->next()) {
if (Token::simpleMatch(tok, "sizeof (")) {
ValueType vt = ValueType::parseDecl(tok->tokAt(2), settings);
const int sz = vt.typeSize(settings.platform, true);
const MathLib::bigint sz = vt.typeSize(settings.platform, true);
if (sz <= 0)
continue;
long long mul = 1;
Expand Down
4 changes: 2 additions & 2 deletions lib/findtoken.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ bool findTokensSkipDeadCodeImpl(const Library& library,
if (Token::simpleMatch(thenStart->link(), "} else {"))
elseStart = thenStart->link()->tokAt(2);

int r = result.front();
auto r = result.front();
if (r == 0) {
if (elseStart) {
if (findTokensSkipDeadCodeImpl(library, elseStart, elseStart->link(), pred, found, evaluate, skipUnevaluated))
Expand Down Expand Up @@ -154,7 +154,7 @@ bool findTokensSkipDeadCodeImpl(const Library& library,
continue;
if (isReturnScope(tok->link(), library))
return true;
int r = result.front();
auto r = result.front();
if (r != 0) {
tok = tok->linkAt(2);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/forwardanalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ namespace {
return std::make_pair(false, false);
std::vector<MathLib::bigint> result = analyzer->evaluate(tok, ctx);
// TODO: We should convert to bool
const bool checkThen = std::any_of(result.cbegin(), result.cend(), [](int x) {
const bool checkThen = std::any_of(result.cbegin(), result.cend(), [](MathLib::bigint x) {
return x != 0;
});
const bool checkElse = std::any_of(result.cbegin(), result.cend(), [](int x) {
const bool checkElse = std::any_of(result.cbegin(), result.cend(), [](MathLib::bigint x) {
return x == 0;
});
return std::make_pair(checkThen, checkElse);
Expand Down
2 changes: 1 addition & 1 deletion lib/mathlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class CPPCHECKLIB MathLib {
/** @brief value class */
class value {
private:
long long mIntValue{};
bigint mIntValue{};
double mDoubleValue{};
enum class Type : std::uint8_t { INT, LONG, LONGLONG, FLOAT } mType;
bool mIsUnsigned{};
Expand Down
15 changes: 8 additions & 7 deletions lib/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
//---------------------------------------------------------------------------

#include "config.h"
#include "mathlib.h"
#include "standards.h"

#include <climits>
Expand Down Expand Up @@ -66,26 +67,26 @@ class CPPCHECKLIB Platform {
public:
Platform();

bool isIntValue(long long value) const {
bool isIntValue(MathLib::bigint value) const {
return value >= min_value(int_bit) && value <= max_value(int_bit);
}

bool isIntValue(unsigned long long value) const {
bool isIntValue(MathLib::biguint value) const {
const unsigned long long intMax = max_value(int_bit);
return value <= intMax;
}

bool isLongValue(long long value) const {
bool isLongValue(MathLib::bigint value) const {
return value >= min_value(long_bit) && value <= max_value(long_bit);
}

bool isLongValue(unsigned long long value) const {
const unsigned long long longMax = max_value(long_bit);
bool isLongValue(MathLib::biguint value) const {
const MathLib::biguint longMax = max_value(long_bit);
return value <= longMax;
}

bool isLongLongValue(unsigned long long value) const {
const unsigned long long longLongMax = max_value(long_long_bit);
bool isLongLongValue(MathLib::biguint value) const {
const MathLib::biguint longLongMax = max_value(long_long_bit);
return value <= longLongMax;
}

Expand Down
4 changes: 2 additions & 2 deletions lib/reverseanalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ namespace {
std::pair<bool, bool> evalCond(const Token* tok) const {
std::vector<MathLib::bigint> result = analyzer->evaluate(tok);
// TODO: We should convert to bool
const bool checkThen = std::any_of(result.cbegin(), result.cend(), [](int x) {
const bool checkThen = std::any_of(result.cbegin(), result.cend(), [](MathLib::bigint x) {
return x == 1;
});
const bool checkElse = std::any_of(result.cbegin(), result.cend(), [](int x) {
const bool checkElse = std::any_of(result.cbegin(), result.cend(), [](MathLib::bigint x) {
return x == 0;
});
return std::make_pair(checkThen, checkElse);
Expand Down
10 changes: 5 additions & 5 deletions lib/valueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6348,7 +6348,7 @@ static std::vector<ValueFlow::Value> getContainerValues(const Token* tok)
return values;
}

static ValueFlow::Value makeContainerSizeValue(std::size_t s, bool known = true)
static ValueFlow::Value makeContainerSizeValue(MathLib::bigint s, bool known = true)
{
ValueFlow::Value value(s);
value.valueType = ValueFlow::Value::ValueType::CONTAINER_SIZE;
Expand Down Expand Up @@ -6382,7 +6382,7 @@ static std::vector<ValueFlow::Value> getContainerSizeFromConstructorArgs(const s
// (ptr, ptr) is empty
// TODO: Use lifetime values to check if it points to the same address
if (args[0]->exprId() == args[1]->exprId())
return {makeContainerSizeValue(std::size_t{0}, known)};
return {makeContainerSizeValue(MathLib::bigint{0}, known)};
// TODO: Insert iterator positions for pointers
if (Token::simpleMatch(args[1], "+")) {
nonneg int const eid = args[0]->exprId();
Expand Down Expand Up @@ -6427,7 +6427,7 @@ static std::vector<ValueFlow::Value> getInitListSize(const Token* tok,
{
std::vector<const Token*> args = getArguments(tok);
if (args.empty())
return {makeContainerSizeValue(std::size_t{0}, known)};
return {makeContainerSizeValue(MathLib::bigint{0}, known)};
bool initList = tok->str() == "{";
// Try to disambiguate init list from constructor
if (initList && args.size() < 4) {
Expand Down Expand Up @@ -6461,7 +6461,7 @@ static std::vector<ValueFlow::Value> getContainerSizeFromConstructor(const Token
{
std::vector<const Token*> args = getArguments(tok);
if (args.empty())
return {makeContainerSizeValue(std::size_t{0}, known)};
return {makeContainerSizeValue(MathLib::bigint{0}, known)};
// Init list in constructor
if (args.size() == 1 && Token::simpleMatch(args[0], "{"))
return getInitListSize(args[0], valueType, settings, known);
Expand Down Expand Up @@ -6511,7 +6511,7 @@ static void valueFlowContainerSize(const TokenList& tokenlist,
continue;

bool known = true;
int size = 0;
MathLib::bigint size = 0;
const bool nonLocal = !var->isLocal() || var->isPointer() || var->isReference() || var->isStatic();
bool constSize = var->isConst() && !nonLocal;
bool staticSize = false;
Expand Down
4 changes: 2 additions & 2 deletions lib/vf_analyzers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ struct ValueFlowAnalyzer : Analyzer {
if (dst) {
const size_t sz = ValueFlow::getSizeOf(*dst, settings);
if (sz > 0 && sz < sizeof(MathLib::biguint)) {
long long newvalue = ValueFlow::truncateIntValue(value->intvalue, sz, dst->sign);
MathLib::bigint newvalue = ValueFlow::truncateIntValue(value->intvalue, sz, dst->sign);

/* Handle overflow/underflow for value bounds */
if (value->bound != ValueFlow::Value::Bound::Point) {
Expand Down Expand Up @@ -1482,7 +1482,7 @@ struct ContainerExpressionAnalyzer : ExpressionAnalyzer {
return;
const Token* parent = tok->astParent();
const Library::Container* container = getLibraryContainer(tok);
int n = 0;
MathLib::bigint n = 0;

if (container->stdStringLike && Token::simpleMatch(parent, "+=") && parent->astOperand2()) {
const Token* rhs = parent->astOperand2();
Expand Down
2 changes: 1 addition & 1 deletion lib/vf_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ namespace ValueFlow
return true;
}

long long truncateIntValue(long long value, size_t value_size, const ValueType::Sign dst_sign)
MathLib::bigint truncateIntValue(MathLib::bigint value, size_t value_size, const ValueType::Sign dst_sign)
{
if (value_size == 0)
return value;
Expand Down
2 changes: 1 addition & 1 deletion lib/vf_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace ValueFlow
{
bool getMinMaxValues(const ValueType* vt, const Platform& platform, MathLib::bigint& minValue, MathLib::bigint& maxValue);

long long truncateIntValue(long long value, size_t value_size, const ValueType::Sign dst_sign);
MathLib::bigint truncateIntValue(MathLib::bigint value, size_t value_size, const ValueType::Sign dst_sign);

Token * valueFlowSetConstantValue(Token *tok, const Settings &settings);

Expand Down
4 changes: 2 additions & 2 deletions lib/vf_settokenvalue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ namespace ValueFlow
const ValueType *dst = tok->valueType();
if (dst) {
const size_t sz = ValueFlow::getSizeOf(*dst, settings);
long long newvalue = ValueFlow::truncateIntValue(v.intvalue + 1, sz, dst->sign);
MathLib::bigint newvalue = ValueFlow::truncateIntValue(v.intvalue + 1, sz, dst->sign);
if (v.bound != ValueFlow::Value::Bound::Point) {
if (newvalue < v.intvalue) {
v.invertBound();
Expand Down Expand Up @@ -671,7 +671,7 @@ namespace ValueFlow
const ValueType *dst = tok->valueType();
if (dst) {
const size_t sz = ValueFlow::getSizeOf(*dst, settings);
long long newvalue = ValueFlow::truncateIntValue(v.intvalue - 1, sz, dst->sign);
MathLib::bigint newvalue = ValueFlow::truncateIntValue(v.intvalue - 1, sz, dst->sign);
if (v.bound != ValueFlow::Value::Bound::Point) {
if (newvalue > v.intvalue) {
v.invertBound();
Expand Down
2 changes: 1 addition & 1 deletion lib/vfvalue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <string>

namespace ValueFlow {
Value::Value(const Token *c, long long val, Bound b)
Value::Value(const Token *c, MathLib::bigint val, Bound b)
: bound(b),
safe(false),
conditional(false),
Expand Down
Loading