Fixed #6341: false negative uninitvar pattern "return foo ( %var%"
This commit is contained in:
parent
4cbbca3db0
commit
2e45df3b72
|
@ -1,5 +1,14 @@
|
|||
<?xml version="1.0"?>
|
||||
<def format="1">
|
||||
<!-- wint_t btowc (int c); -->
|
||||
<!-- A function to convert a single byte character to a wide character. -->
|
||||
<function name="btowc">
|
||||
<noreturn>false</noreturn>
|
||||
<arg nr="1">
|
||||
<not-uninit/>
|
||||
</arg>
|
||||
<leak-ignore/>
|
||||
</function>
|
||||
<function name="usleep">
|
||||
<noreturn>false</noreturn>
|
||||
<arg nr="1">
|
||||
|
|
|
@ -1449,9 +1449,7 @@ bool CheckUninitVar::checkScopeForVariable(const Scope* scope, const Token *tok,
|
|||
uninitdataError(tok, tok->str());
|
||||
else
|
||||
uninitvarError(tok, tok->str());
|
||||
}
|
||||
|
||||
else
|
||||
} else
|
||||
// assume that variable is assigned
|
||||
return true;
|
||||
}
|
||||
|
@ -1666,6 +1664,11 @@ bool CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer, bool all
|
|||
if (!alloc && vartok->previous()->str() == "return")
|
||||
return true;
|
||||
|
||||
// code like: return foo( variable
|
||||
if (vartok->tokAt(-3) && vartok->tokAt(-3)->str() == "return"
|
||||
&& vartok->tokAt(-1) && vartok->tokAt(-1)->str() == "(")
|
||||
return true;
|
||||
|
||||
// Passing variable to typeof/__alignof__
|
||||
if (Token::Match(vartok->tokAt(-3), "typeof|__alignof__ ( * %var%"))
|
||||
return false;
|
||||
|
|
|
@ -73,6 +73,7 @@ private:
|
|||
TEST_CASE(syntax_error); // Ticket #5073
|
||||
|
||||
// Test that the functions from std.cfg are configured correctly
|
||||
TEST_CASE(stdcfg_btowc);
|
||||
TEST_CASE(stdcfg_clearerr);
|
||||
TEST_CASE(stdcfg_fclose);
|
||||
TEST_CASE(stdcfg_fopen);
|
||||
|
@ -3610,6 +3611,15 @@ private:
|
|||
ASSERT_EQUALS("[test.cpp:6]: (debug) assertion failed '} while ('\n", errout.str());
|
||||
}
|
||||
|
||||
// Test that the btowc function, defined in std.cfg is configured correctly.
|
||||
void stdcfg_btowc() {
|
||||
checkUninitVar2("wchar_t f() { int i; return btowc(i); }");
|
||||
ASSERT_EQUALS("[test.cpp:1]: (error) Uninitialized variable: i\n", errout.str());
|
||||
|
||||
checkUninitVar2("wchar_t f(int i) { return btowc(i); }");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
// Test that the clearerr function, defined in std.cfg is configured correctly.
|
||||
void stdcfg_clearerr() {
|
||||
checkUninitVar("void f() {\n"
|
||||
|
|
Loading…
Reference in New Issue