library: fixed handling of indirect attribute

This commit is contained in:
Daniel Marjamäki 2020-06-07 20:18:54 +02:00
parent 1705d096f7
commit ca8b5f49f3
3 changed files with 8 additions and 5 deletions

View File

@ -1183,9 +1183,10 @@ int CheckUninitVar::isFunctionParUsage(const Token *vartok, bool pointer, Alloc
const bool isnullbad = mSettings->library.isnullargbad(start->previous(), argumentNumber + 1);
if (indirect == 0 && pointer && !address && isnullbad && alloc == NO_ALLOC)
return 1;
const bool isuninitbad = mSettings->library.isuninitargbad(start->previous(), argumentNumber + 1, indirect);
bool hasIndirect = false;
const bool isuninitbad = mSettings->library.isuninitargbad(start->previous(), argumentNumber + 1, indirect, &hasIndirect);
if (alloc != NO_ALLOC)
return isnullbad && isuninitbad;
return (isnullbad || hasIndirect) && isuninitbad;
return isuninitbad && (!address || isnullbad);
}
}

View File

@ -692,7 +692,7 @@ Library::Error Library::loadFunction(const tinyxml2::XMLElement * const node, co
for (const tinyxml2::XMLElement *argnode = functionnode->FirstChildElement(); argnode; argnode = argnode->NextSiblingElement()) {
const std::string argnodename = argnode->Name();
int indirect = 0;
const char * const indirectStr = node->Attribute("indirect");
const char * const indirectStr = argnode->Attribute("indirect");
if (indirectStr)
indirect = atoi(indirectStr);
if (argnodename == "not-bool")
@ -1035,7 +1035,7 @@ bool Library::isnullargbad(const Token *ftok, int argnr) const
return arg && arg->notnull;
}
bool Library::isuninitargbad(const Token *ftok, int argnr, int indirect) const
bool Library::isuninitargbad(const Token *ftok, int argnr, int indirect, bool *hasIndirect) const
{
const ArgumentChecks *arg = getarg(ftok, argnr);
if (!arg) {
@ -1045,6 +1045,8 @@ bool Library::isuninitargbad(const Token *ftok, int argnr, int indirect) const
if (it != functions.cend() && it->second.formatstr && !it->second.formatstr_scan)
return true;
}
if (hasIndirect && arg && arg->notuninit >= 1)
*hasIndirect = true;
return arg && arg->notuninit >= indirect;
}

View File

@ -324,7 +324,7 @@ public:
}
bool isnullargbad(const Token *ftok, int argnr) const;
bool isuninitargbad(const Token *ftok, int argnr, int indirect = 0) const;
bool isuninitargbad(const Token *ftok, int argnr, int indirect = 0, bool *hasIndirect=nullptr) const;
bool isargformatstr(const Token *ftok, int argnr) const {
const ArgumentChecks *arg = getarg(ftok, argnr);