Fixed #7012 (False positive uninitvar - first argument to snprintf)

This commit is contained in:
Daniel Marjamäki 2015-10-03 18:35:16 +02:00
parent a574fda8a9
commit 28e3c266b3
3 changed files with 17 additions and 8 deletions

View File

@ -3753,11 +3753,12 @@
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1">
<not-uninit/>
<not-null/>
<minsize type="argvalue" arg="2"/>
</arg>
<arg nr="2">
<not-uninit/>
<valid>1:</valid>
</arg>
<formatstr/>
<arg nr="3">
@ -3765,9 +3766,6 @@
<not-null/>
<not-uninit/>
</arg>
<arg nr="any">
<not-uninit/>
</arg>
</function>
<!-- int vsnprintf(char *s, size_t n, const char *format, va_list arg); -->
<function name="vsnprintf,std::vsnprintf">

View File

@ -683,6 +683,20 @@ static std::string functionName(const Token *ftok)
return ret;
}
bool Library::isuninitargbad(const Token *ftok, int argnr) const
{
const ArgumentChecks *arg = getarg(ftok, argnr);
if (!arg) {
// non-scan format string argument should not be uninitialized
const std::string funcname = functionName(ftok);
std::map<std::string, std::pair<bool, bool> >::const_iterator it = _formatstr.find(funcname);
if (it != _formatstr.end() && !it->second.first)
return true;
}
return arg && arg->notuninit;
}
/** get allocation id for function */
int Library::alloc(const Token *tok) const
{

View File

@ -217,10 +217,7 @@ public:
return arg && arg->notnull;
}
bool isuninitargbad(const Token *ftok, int argnr) const {
const ArgumentChecks *arg = getarg(ftok, argnr);
return arg && arg->notuninit;
}
bool isuninitargbad(const Token *ftok, int argnr) const;
bool isargformatstr(const Token *ftok, int argnr) const {
const ArgumentChecks *arg = getarg(ftok, argnr);