From a6b0129725856bcac3135f2ddb8a39f11c3b45db Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 20 Jul 2023 10:45:44 +0200 Subject: [PATCH] Fix #11838 FP uninitvar with label matching variable name (#5251) --- lib/tokenize.cpp | 3 ++- test/testvarid.cpp | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 4bb7268f5..b49aa46e4 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -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::const_iterator it = variableMap.map(globalNamespace).find(tok->str()); if (it != variableMap.map(globalNamespace).end()) { tok->varId(it->second); diff --git a/test/testvarid.cpp b/test/testvarid.cpp index e0ffc1500..90dfeafe6 100644 --- a/test/testvarid.cpp +++ b/test/testvarid.cpp @@ -2785,6 +2785,17 @@ private: " break;\n" " }\n" "}", "test.c")); + + ASSERT_EQUALS("1: int * f ( ) {\n" // #11838 + "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