Skip to content

Commit 20a3824

Browse files
committed
fixed #13734 - FP unsignedLessThanZero for unknown array size [skip ci]
1 parent 5a9d0b3 commit 20a3824

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

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_);

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() {

0 commit comments

Comments
 (0)