Fixed #1776 (False Negative: Unitialized array)
This commit is contained in:
parent
b5d0955d11
commit
cb7e9fbec1
|
@ -2936,7 +2936,7 @@ private:
|
||||||
!Token::simpleMatch(tok2->next(), "="))
|
!Token::simpleMatch(tok2->next(), "="))
|
||||||
{
|
{
|
||||||
bool foundError;
|
bool foundError;
|
||||||
if (tok2->next()->str() == "[")
|
if (tok2->previous()->str() == "*" || tok2->next()->str() == "[")
|
||||||
foundError = use_array_or_pointer_data(checks, tok2);
|
foundError = use_array_or_pointer_data(checks, tok2);
|
||||||
else
|
else
|
||||||
foundError = use(checks, tok2);
|
foundError = use(checks, tok2);
|
||||||
|
@ -3058,7 +3058,7 @@ private:
|
||||||
return tok.next()->link();
|
return tok.next()->link();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Token::Match(&tok, "asm ( )"))
|
if (Token::simpleMatch(&tok, "asm ( )"))
|
||||||
{
|
{
|
||||||
ExecutionPath::bailOut(checks);
|
ExecutionPath::bailOut(checks);
|
||||||
return &tok;
|
return &tok;
|
||||||
|
|
|
@ -3577,7 +3577,8 @@ bool Tokenizer::simplifyTokenList()
|
||||||
if (! next)
|
if (! next)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (Token::Match(next, "* ( %var% + %num% )"))
|
if (Token::Match(next, "* ( %var% + %num% )") ||
|
||||||
|
Token::Match(next, "* ( %var% + %var% )"))
|
||||||
{
|
{
|
||||||
// var
|
// var
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
|
|
|
@ -1799,6 +1799,13 @@ private:
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: a\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: a\n", errout.str());
|
||||||
|
|
||||||
|
checkUninitVar("int f()\n"
|
||||||
|
"{\n"
|
||||||
|
" char a[10];\n"
|
||||||
|
" char c = *a;\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: a\n", errout.str());
|
||||||
|
|
||||||
checkUninitVar("int f()\n"
|
checkUninitVar("int f()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" char a[10];\n"
|
" char a[10];\n"
|
||||||
|
|
|
@ -43,6 +43,9 @@ private:
|
||||||
TEST_CASE(tokenize4);
|
TEST_CASE(tokenize4);
|
||||||
TEST_CASE(tokenize5);
|
TEST_CASE(tokenize5);
|
||||||
|
|
||||||
|
// array access. replace "*(p+1)" => "p[1]"
|
||||||
|
TEST_CASE(tokenize6);
|
||||||
|
|
||||||
// don't freak out when the syntax is wrong
|
// don't freak out when the syntax is wrong
|
||||||
TEST_CASE(wrong_syntax);
|
TEST_CASE(wrong_syntax);
|
||||||
|
|
||||||
|
@ -327,6 +330,13 @@ private:
|
||||||
ASSERT_EQUALS("; 1E-2 ;", tokenizeAndStringify("; 1E-2 ;"));
|
ASSERT_EQUALS("; 1E-2 ;", tokenizeAndStringify("; 1E-2 ;"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tokenize6()
|
||||||
|
{
|
||||||
|
// "*(p+1)" => "p[1]"
|
||||||
|
ASSERT_EQUALS("; x = p [ 1 ] ;", tokenizeAndStringify("; x = * ( p + 1 ) ;", true));
|
||||||
|
ASSERT_EQUALS("; x = p [ n ] ;", tokenizeAndStringify("; x = * ( p + n ) ;", true));
|
||||||
|
}
|
||||||
|
|
||||||
void wrong_syntax()
|
void wrong_syntax()
|
||||||
{
|
{
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
Loading…
Reference in New Issue