Fix issue 9855: false positive: uninitvar (#2754)

This commit is contained in:
Paul Fultz II 2020-08-26 00:02:15 -05:00 committed by GitHub
parent 7cf3909275
commit 9ec27c112f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View File

@ -209,6 +209,7 @@ struct ForwardTraversal {
} }
Progress updateLoop(Token* endBlock, Token* condTok, Token* initTok = nullptr, Token* stepTok = nullptr) { Progress updateLoop(Token* endBlock, Token* condTok, Token* initTok = nullptr, Token* stepTok = nullptr) {
const bool isDoWhile = precedes(endBlock, condTok);
ForwardAnalyzer::Action bodyAnalysis = analyzeScope(endBlock); ForwardAnalyzer::Action bodyAnalysis = analyzeScope(endBlock);
ForwardAnalyzer::Action allAnalysis = bodyAnalysis; ForwardAnalyzer::Action allAnalysis = bodyAnalysis;
if (condTok) if (condTok)
@ -225,7 +226,7 @@ struct ForwardTraversal {
return Progress::Break; return Progress::Break;
} }
// Traverse condition after lowering // Traverse condition after lowering
if (condTok) { if (condTok && (!isDoWhile || !bodyAnalysis.isModified())) {
if (updateRecursive(condTok) == Progress::Break) if (updateRecursive(condTok) == Progress::Break)
return Progress::Break; return Progress::Break;

View File

@ -4430,6 +4430,16 @@ private:
" f += 1;\n" " f += 1;\n"
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
valueFlowUninit("unsigned char get();\n"
"char f() {\n"
" unsigned char c;\n"
" do {\n"
" c = get();\n"
" } while (isalpha(c) == 0);\n"
" return static_cast<char>(c);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
} }
void uninitvar_ipa() { void uninitvar_ipa() {