Skip to content

Commit

Permalink
Fix #11838 FP uninitvar with label matching variable name
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Jul 19, 2023
1 parent d2546d5 commit 59365ad
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4757,7 +4757,8 @@ void Tokenizer::setVarIdPass1()
continue;
}

if (!scopeStack.top().isEnum || !(Token::Match(tok->previous(), "{|,") && Token::Match(tok->next(), ",|=|}"))) {
if ((!scopeStack.top().isEnum || !(Token::Match(tok->previous(), "{|,") && Token::Match(tok->next(), ",|=|}"))) &&
!Token::simpleMatch(tok->next(), ": ;")) {
const std::map<std::string, nonneg int>::const_iterator it = variableMap.map(globalNamespace).find(tok->str());
if (it != variableMap.map(globalNamespace).end()) {
tok->varId(it->second);
Expand Down
11 changes: 11 additions & 0 deletions test/testvarid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2785,6 +2785,17 @@ class TestVarID : public TestFixture {
" break;\n"
" }\n"
"}", "test.c"));

ASSERT_EQUALS("1: int * f ( ) {\n"
"2: int * label@1 ; label@1 = 0 ;\n"
"3: label : ;\n"
"4: return label@1 ;\n"
"5: }\n",
tokenize("int* f() {\n"
" int* label = 0;\n"
"label:\n"
" return label;\n"
"}"));
}

void varid_structinit() { // #6406
Expand Down

0 comments on commit 59365ad

Please sign in to comment.