From 4656eba34cfbdc7ed46842a6184918c94598e1aa Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Thu, 23 Jun 2011 22:35:15 -0400 Subject: [PATCH] set symbol database array variable dimensions specified by a variable to the maximum size that variable can hold --- lib/symboldatabase.cpp | 74 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 30e6b351d..2660cef37 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -31,6 +31,7 @@ #include #include #include +#include //--------------------------------------------------------------------------- @@ -801,6 +802,79 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti } } } + + /* set all unknown array dimensions that are set by a variable to the maximum size of that variable type */ + for (size_t i = 1; i <= _tokenizer->varIdCount(); i++) + { + // check each array variable + if (_variableList[i] && _variableList[i]->isArray()) + { + // check each array dimension + for (size_t j = 0; j < _variableList[i]->dimensions().size(); j++) + { + // check for a single token dimension that is a variable + if ((_variableList[i]->dimensions()[j].start == _variableList[i]->dimensions()[j].end) && + _variableList[i]->dimensions()[j].start->varId()) + { + Dimension &dimension = const_cast(_variableList[i]->dimensions()[j]); + + // get maximum size from type + // find where this type is defined + const Variable *var = getVariableFromVarId(dimension.start->varId()); + + // make sure it is in the database + if (!var) + break; + + // get type token + const Token *index_type = var->typeEndToken(); + + if (index_type->str() == "char") + { + if (index_type->isUnsigned()) + dimension.num = UCHAR_MAX + 1; + else if (index_type->isSigned()) + dimension.num = SCHAR_MAX + 1; + else + dimension.num = CHAR_MAX + 1; + } + else if (index_type->str() == "short") + { + if (index_type->isUnsigned()) + dimension.num = USHRT_MAX + 1; + else + dimension.num = SHRT_MAX + 1; + } + + // checkScope assumes size is signed int so we limit the following sizes to INT_MAX + else if (index_type->str() == "int") + { + if (index_type->isUnsigned()) + dimension.num = UINT_MAX + 1ULL; + else + dimension.num = INT_MAX + 1ULL; + } + else if (index_type->str() == "long") + { + if (index_type->isUnsigned()) + { + if (index_type->isLong()) + dimension.num = ULLONG_MAX; // should be ULLONG_MAX + 1ULL; + else + dimension.num = ULONG_MAX + 1ULL; + } + else + { + if (index_type->isLong()) + dimension.num = LLONG_MAX; // should be LLONG_MAX + 1LL; + else + dimension.num = LONG_MAX + 1LL; + } + } + } + } + } + } } bool SymbolDatabase::isFunction(const Token *tok, const Token **funcStart, const Token **argStart) const