Skip to content

Commit b0d4f8f

Browse files
fixed #13734 - FP unsignedLessThanZero for unknown array size
Co-authored-by: chrchr-github <[email protected]>
1 parent 06f6f1c commit b0d4f8f

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

Diff for: lib/symboldatabase.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -3747,13 +3747,15 @@ bool Variable::arrayDimensions(const Settings& settings, bool& isContainer)
37473747
// TODO: collect timing information for this call?
37483748
ValueFlow::valueFlowConstantFoldAST(const_cast<Token *>(dimension_.tok), settings);
37493749
if (dimension_.tok) {
3750-
if (const ValueFlow::Value* v = dimension_.tok->getKnownValue(ValueFlow::Value::ValueType::INT))
3750+
if (const ValueFlow::Value* v = dimension_.tok->getKnownValue(ValueFlow::Value::ValueType::INT)) {
37513751
dimension_.num = v->intvalue;
3752+
dimension_.known = true;
3753+
}
37523754
else if (dimension_.tok->isTemplateArg() && !dimension_.tok->values().empty()) {
37533755
assert(dimension_.tok->values().size() == 1);
37543756
dimension_.num = dimension_.tok->values().front().intvalue;
3757+
dimension_.known = true;
37553758
}
3756-
dimension_.known = true;
37573759
}
37583760
}
37593761
mDimensions.push_back(dimension_);

Diff for: test/testother.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -8852,6 +8852,13 @@ class TestOther : public TestFixture {
88528852
" f<uint32_t>(0);\n"
88538853
"}");
88548854
ASSERT_EQUALS("", errout_str());
8855+
8856+
// #13734
8857+
check("void f() {\n"
8858+
" uint8_t a[N + 1];\n"
8859+
" for (unsigned p = 0; p < (sizeof(a) / sizeof((a)[0])); ++p) {}\n"
8860+
"}");
8861+
ASSERT_EQUALS("", errout_str());
88558862
}
88568863

88578864
void checkSignOfPointer() {

Diff for: test/testvalueflow.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -1687,6 +1687,16 @@ class TestValueFlow : public TestFixture {
16871687
values = tokenValues(code, "=");
16881688
ASSERT_EQUALS(1U, values.size());
16891689
ASSERT_EQUALS(4LL * 5, values.back().intvalue);
1690+
1691+
// #13734
1692+
code = "void f() {\n"
1693+
" int a[N + 1];"
1694+
" x = sizeof(a) / sizeof(a[0]);\n"
1695+
"}";
1696+
values = tokenValues(code,"/");
1697+
ASSERT_EQUALS(1U, values.size());
1698+
ASSERT_EQUALS(-1, values.back().intvalue);
1699+
ASSERT_EQUALS_ENUM(ValueFlow::Value::ValueKind::Impossible, values.back().valueKind);
16901700
}
16911701

16921702
void valueFlowComma()

0 commit comments

Comments
 (0)