Fix 11285: FN: zerodiv (#4448)

* Fix 11285: FN: zerodiv

* Format
This commit is contained in:
Paul Fultz II 2022-09-07 12:15:37 -05:00 committed by GitHub
parent 54771306c5
commit 6543b429c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 1 deletions

View File

@ -7578,7 +7578,7 @@ struct ContainerExpressionAnalyzer : ExpressionAnalyzer {
if (isLikelyStreamRead(isCPP(), tok->astParent()))
return Action::Invalid;
if (astIsContainer(tok) && isContainerSizeChanged(tok, getSettings()))
return Action::Invalid;
return read | Action::Invalid;
return read;
}
};

View File

@ -2661,6 +2661,26 @@ private:
"}";
ASSERT_EQUALS(true, testValueOfXKnown(code, 6U, 1));
ASSERT_EQUALS(false, testValueOfXKnown(code, 6U, 2));
code = "int f() {\n"
" std::string a;\n"
" std::string b=\"42\";\n"
" std::swap(b, a);\n"
" int x = b.size();\n"
" return x;\n"
"}\n";
ASSERT_EQUALS(true, testValueOfXKnown(code, 6U, 0));
ASSERT_EQUALS(false, testValueOfXKnown(code, 6U, 2));
code = "int f() {\n"
" std::string a;\n"
" std::string b=\"42\";\n"
" std::swap(b, a);\n"
" int x = a.size();\n"
" return x;\n"
"}\n";
ASSERT_EQUALS(true, testValueOfXKnown(code, 6U, 2));
ASSERT_EQUALS(false, testValueOfXKnown(code, 6U, 0));
}
void valueFlowAfterCondition() {