Fixed false positive #4163
This commit is contained in:
parent
1e5d082251
commit
e9f13e1547
|
@ -502,10 +502,10 @@ void CheckIO::checkWrongPrintfScanfArguments()
|
|||
if ((!variableInfo->isPointer() && !variableInfo->isArray()) || varTypeTok->strAt(-1) == "const")
|
||||
invalidScanfArgTypeError(tok, tok->str(), numFormat);
|
||||
|
||||
if (*i == 's' && variableInfo && isKnownType(variableInfo, varTypeTok) && variableInfo->isArray() && (variableInfo->dimensions().size() == 1)) {
|
||||
if (*i == 's' && variableInfo && isKnownType(variableInfo, varTypeTok) && variableInfo->isArray() && (variableInfo->dimensions().size() == 1) && variableInfo->dimensions()[0].known) {
|
||||
if (!width.empty()) {
|
||||
int numWidth = std::atoi(width.c_str());
|
||||
if (numWidth != (variableInfo->dimension(0) - 1))
|
||||
if (numWidth != (variableInfo->dimension(0) - 1))
|
||||
invalidScanfFormatWidthError(tok, numFormat, numWidth, variableInfo);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -748,11 +748,12 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
|
|||
if (_variableList[i] && _variableList[i]->isArray()) {
|
||||
// check each array dimension
|
||||
for (std::size_t j = 0; j < _variableList[i]->dimensions().size(); j++) {
|
||||
Dimension &dimension = const_cast<Dimension &>(_variableList[i]->dimensions()[j]);
|
||||
// check for a single token dimension that is a variable
|
||||
if (_variableList[i]->dimensions()[j].start &&
|
||||
(_variableList[i]->dimensions()[j].start == _variableList[i]->dimensions()[j].end) &&
|
||||
_variableList[i]->dimensions()[j].start->varId()) {
|
||||
Dimension &dimension = const_cast<Dimension &>(_variableList[i]->dimensions()[j]);
|
||||
if (dimension.num == 0) {
|
||||
dimension.known = false;
|
||||
if (!dimension.start || (dimension.start != dimension.end) || !dimension.start->varId())
|
||||
continue;
|
||||
|
||||
// get maximum size from type
|
||||
// find where this type is defined
|
||||
|
@ -1372,6 +1373,8 @@ void SymbolDatabase::printVariable(const Variable *var, const char *indent) cons
|
|||
std::cout << indent << "_dimensions:";
|
||||
for (std::size_t i = 0; i < var->dimensions().size(); i++) {
|
||||
std::cout << " " << var->dimension(i);
|
||||
if (!var->dimensions()[i].known)
|
||||
std::cout << "?";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
|
|
@ -46,11 +46,12 @@ enum AccessControl { Public, Protected, Private, Global, Namespace, Argument, Lo
|
|||
* @brief Array dimension information.
|
||||
*/
|
||||
struct Dimension {
|
||||
Dimension() : start(NULL), end(NULL), num(0) { }
|
||||
Dimension() : start(NULL), end(NULL), num(0), known(true) { }
|
||||
|
||||
const Token *start; // size start token
|
||||
const Token *end; // size end token
|
||||
MathLib::bigint num; // dimension length when size is a number, 0 if not known
|
||||
MathLib::bigint num; // (assumpted) dimension length when size is a number, 0 if not known
|
||||
bool known; // Known size
|
||||
};
|
||||
|
||||
/** @brief Information about a member variable. */
|
||||
|
|
Loading…
Reference in New Issue