Fixed #2743 (segmentation fault of cppcheck 'std::vector<void(*)()> v1 = a, v2 = b;')
This commit is contained in:
parent
af7c97f972
commit
8e5c63104c
|
@ -236,10 +236,22 @@ unsigned int Tokenizer::sizeOfType(const Token *type) const
|
|||
|
||||
void Tokenizer::insertTokens(Token *dest, const Token *src, unsigned int n)
|
||||
{
|
||||
std::stack<Token *> link;
|
||||
|
||||
while (n > 0)
|
||||
{
|
||||
dest->insertToken(src->str().c_str());
|
||||
dest->insertToken(src->str());
|
||||
dest = dest->next();
|
||||
|
||||
// Set links
|
||||
if (Token::Match(dest, "(|[|{"))
|
||||
link.push(dest);
|
||||
else if (!link.empty() && Token::Match(dest, ")|]|}"))
|
||||
{
|
||||
Token::createMutualLinks(dest, link.top());
|
||||
link.pop();
|
||||
}
|
||||
|
||||
dest->fileIndex(src->fileIndex());
|
||||
dest->linenr(src->linenr());
|
||||
dest->varId(src->varId());
|
||||
|
|
|
@ -249,6 +249,7 @@ private:
|
|||
TEST_CASE(vardecl_stl_2);
|
||||
TEST_CASE(vardecl_template);
|
||||
TEST_CASE(vardecl_union);
|
||||
TEST_CASE(vardecl_par); // #2743 - set links if variable type contains parentheses
|
||||
TEST_CASE(volatile_variables);
|
||||
TEST_CASE(syntax_error);
|
||||
TEST_CASE(syntax_error_templates_1);
|
||||
|
@ -4096,6 +4097,18 @@ private:
|
|||
ASSERT_EQUALS("void f ( ) {\n\nint x ;\nlong & y = x ;\n\n}", tokenizeAndStringify(code2));
|
||||
}
|
||||
|
||||
void vardecl_par()
|
||||
{
|
||||
// ticket #2743 - set links if variable type contains parentheses
|
||||
const char code[] = "Fred<int(*)()> fred1=a, fred2=b;";
|
||||
|
||||
Settings settings;
|
||||
Tokenizer tokenizer(&settings, this);
|
||||
std::istringstream istr(code);
|
||||
tokenizer.tokenize(istr, "test.cpp", "", false);
|
||||
ASSERT_EQUALS(true, tokenizer.validate());
|
||||
}
|
||||
|
||||
void vardec_static()
|
||||
{
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue