Fixed #2784 (Pointer issue: *&f=open())
This commit is contained in:
parent
b6dcdd7b79
commit
1ea52cfa02
|
@ -2019,6 +2019,28 @@ void Tokenizer::simplifyTypedef()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Tokenizer::simplifyMulAnd(void)
|
||||||
|
{
|
||||||
|
for (Token *tok = _tokens; tok; tok = tok->next())
|
||||||
|
{
|
||||||
|
//fix Ticket #2784
|
||||||
|
if (Token::Match(tok->next(), "* & %any% ="))
|
||||||
|
{
|
||||||
|
tok->deleteNext(); //del *
|
||||||
|
tok->deleteNext(); //del &
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (Token::Match(tok->next(), "* ( & %any% ) ="))
|
||||||
|
{
|
||||||
|
tok->deleteNext(); //del *
|
||||||
|
tok->deleteNext(); //del (
|
||||||
|
tok->deleteNext(); //del &
|
||||||
|
tok->next()->deleteNext(); //del )
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool Tokenizer::tokenize(std::istream &code,
|
bool Tokenizer::tokenize(std::istream &code,
|
||||||
const char FileName[],
|
const char FileName[],
|
||||||
const std::string &configuration,
|
const std::string &configuration,
|
||||||
|
@ -2034,6 +2056,9 @@ bool Tokenizer::tokenize(std::istream &code,
|
||||||
|
|
||||||
createTokens(code);
|
createTokens(code);
|
||||||
|
|
||||||
|
// simplify '* & %any% =' to '%any% ='
|
||||||
|
simplifyMulAnd();
|
||||||
|
|
||||||
// Convert C# code
|
// Convert C# code
|
||||||
if (_files[0].find(".cs"))
|
if (_files[0].find(".cs"))
|
||||||
{
|
{
|
||||||
|
|
|
@ -114,6 +114,11 @@ public:
|
||||||
*/
|
*/
|
||||||
static void deleteTokens(Token *tok);
|
static void deleteTokens(Token *tok);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simplify '* & %any% =' to '%any% ='
|
||||||
|
*/
|
||||||
|
void simplifyMulAnd(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get parameter name of function
|
* Get parameter name of function
|
||||||
* @param ftok The token for the function name in a function
|
* @param ftok The token for the function name in a function
|
||||||
|
|
|
@ -230,6 +230,7 @@ private:
|
||||||
TEST_CASE(simplify_constants2);
|
TEST_CASE(simplify_constants2);
|
||||||
TEST_CASE(simplify_constants3);
|
TEST_CASE(simplify_constants3);
|
||||||
TEST_CASE(simplify_null);
|
TEST_CASE(simplify_null);
|
||||||
|
TEST_CASE(simplifyMulAnd); // #2784
|
||||||
|
|
||||||
TEST_CASE(vardecl1);
|
TEST_CASE(vardecl1);
|
||||||
TEST_CASE(vardecl2);
|
TEST_CASE(vardecl2);
|
||||||
|
@ -4001,6 +4002,23 @@ private:
|
||||||
ASSERT_EQUALS(expected, tokenizeAndStringify(code,true));
|
ASSERT_EQUALS(expected, tokenizeAndStringify(code,true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void simplifyMulAnd()
|
||||||
|
{
|
||||||
|
// (error) Resource leak
|
||||||
|
ASSERT_EQUALS(
|
||||||
|
"void f ( ) { int f ; f = open ( ) ; }",
|
||||||
|
tokenizeAndStringify(
|
||||||
|
"void f() {int f; *&f=open(); }"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
ASSERT_EQUALS(
|
||||||
|
"void f ( ) { int f ; f = open ( ) ; }",
|
||||||
|
tokenizeAndStringify(
|
||||||
|
"void f() {int f; *(&f)=open(); }"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
void vardecl1()
|
void vardecl1()
|
||||||
{
|
{
|
||||||
const char code[] = "unsigned int a, b;";
|
const char code[] = "unsigned int a, b;";
|
||||||
|
|
Loading…
Reference in New Issue