Skip to content

Commit 6543b42

Browse files
authored
Fix 11285: FN: zerodiv (#4448)
* Fix 11285: FN: zerodiv * Format
1 parent 5477130 commit 6543b42

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

lib/valueflow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7578,7 +7578,7 @@ struct ContainerExpressionAnalyzer : ExpressionAnalyzer {
75787578
if (isLikelyStreamRead(isCPP(), tok->astParent()))
75797579
return Action::Invalid;
75807580
if (astIsContainer(tok) && isContainerSizeChanged(tok, getSettings()))
7581-
return Action::Invalid;
7581+
return read | Action::Invalid;
75827582
return read;
75837583
}
75847584
};

test/testvalueflow.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2661,6 +2661,26 @@ class TestValueFlow : public TestFixture {
26612661
"}";
26622662
ASSERT_EQUALS(true, testValueOfXKnown(code, 6U, 1));
26632663
ASSERT_EQUALS(false, testValueOfXKnown(code, 6U, 2));
2664+
2665+
code = "int f() {\n"
2666+
" std::string a;\n"
2667+
" std::string b=\"42\";\n"
2668+
" std::swap(b, a);\n"
2669+
" int x = b.size();\n"
2670+
" return x;\n"
2671+
"}\n";
2672+
ASSERT_EQUALS(true, testValueOfXKnown(code, 6U, 0));
2673+
ASSERT_EQUALS(false, testValueOfXKnown(code, 6U, 2));
2674+
2675+
code = "int f() {\n"
2676+
" std::string a;\n"
2677+
" std::string b=\"42\";\n"
2678+
" std::swap(b, a);\n"
2679+
" int x = a.size();\n"
2680+
" return x;\n"
2681+
"}\n";
2682+
ASSERT_EQUALS(true, testValueOfXKnown(code, 6U, 2));
2683+
ASSERT_EQUALS(false, testValueOfXKnown(code, 6U, 0));
26642684
}
26652685

26662686
void valueFlowAfterCondition() {

0 commit comments

Comments
 (0)