Skip to content

Commit 81c9ac2

Browse files
Fix #14439 FP uninitvar when variable name matches function pointer argument (#8158)
1 parent 3a99f41 commit 81c9ac2

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

lib/tokenize.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5032,8 +5032,8 @@ void Tokenizer::setVarIdPass1()
50325032
// there are tokens which can't appear at the begin of a function declaration such as "return"
50335033
const bool isNotstartKeyword = start->next() && notstart.find(start->strAt(1)) != notstart.end();
50345034

5035-
// now check if it is a function declaration
5036-
if (Token::Match(start, "[;{}] %type% %name%|*") && par && Token::simpleMatch(end, ") ;") && !isNotstartKeyword) {
5035+
// now check if it is a function (pointer) declaration
5036+
if ((Token::simpleMatch(start, ") (") || Token::Match(start, "[;{}] %type% %name%|*")) && par && Token::Match(end, ") [;=]") && !isNotstartKeyword) {
50375037
// function declaration => don't set varid
50385038
tok = end;
50395039
continue;

test/testvarid.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3497,6 +3497,16 @@ class TestVarID : public TestFixture {
34973497

34983498
const char code3[] = "void f (void (*g) (int i, IN int n)) {}\n";
34993499
ASSERT_EQUALS("1: void f ( void ( * g@1 ) ( int , IN int ) ) { }\n", tokenize(code3));
3500+
3501+
const char code4[] = "void f() {\n" // #14439
3502+
" int* p;\n"
3503+
" void (*a[1])(int* p) = { 0 };\n"
3504+
"}\n";
3505+
ASSERT_EQUALS("1: void f ( ) {\n"
3506+
"2: int * p@1 ;\n"
3507+
"3: void ( * a@2 [ 1 ] ) ( int * p ) = { 0 } ;\n"
3508+
"4: }\n",
3509+
tokenize(code4));
35003510
}
35013511

35023512
void varid_alignas() {

0 commit comments

Comments
 (0)