Fix issue 9932: FP: containerOutOfBounds (#3217)
* Fix issue 9932: FP: containerOutOfBounds
This commit is contained in:
parent
9a9043a07e
commit
a772d652d8
|
@ -6295,8 +6295,9 @@ static void valueFlowContainerSize(TokenList *tokenlist, SymbolDatabase* symbold
|
|||
value.valueType = ValueFlow::Value::ValueType::CONTAINER_SIZE;
|
||||
value.setKnown();
|
||||
valueFlowContainerForward(tok->next(), tok->variable(), value, tokenlist);
|
||||
} else if (action == Library::Container::Action::RESIZE && tok->tokAt(4)->hasKnownIntValue()) {
|
||||
ValueFlow::Value value(tok->tokAt(4)->values().front());
|
||||
} else if (action == Library::Container::Action::RESIZE && tok->tokAt(3)->astOperand2() &&
|
||||
tok->tokAt(3)->astOperand2()->hasKnownIntValue()) {
|
||||
ValueFlow::Value value(tok->tokAt(3)->astOperand2()->values().front());
|
||||
value.valueType = ValueFlow::Value::ValueType::CONTAINER_SIZE;
|
||||
value.setKnown();
|
||||
valueFlowContainerForward(tok->next(), tok->variable(), value, tokenlist);
|
||||
|
|
|
@ -5079,6 +5079,16 @@ private:
|
|||
ASSERT_EQUALS("",
|
||||
isPossibleContainerSizeValue(tokenValues(code, "x . front", ValueFlow::Value::ValueType::CONTAINER_SIZE), 0));
|
||||
|
||||
code = "int f() {\n"
|
||||
" const size_t len = 6;\n"
|
||||
" std::vector<char> v;\n"
|
||||
" v.resize(1 + len);\n"
|
||||
" return v.front();\n"
|
||||
"}\n";
|
||||
ASSERT_EQUALS(
|
||||
"",
|
||||
isKnownContainerSizeValue(tokenValues(code, "v . front", ValueFlow::Value::ValueType::CONTAINER_SIZE), 7));
|
||||
|
||||
code = "void f(std::string str) {\n"
|
||||
" if (str == \"123\") {\n"
|
||||
" bool x = (str == \"\");\n"
|
||||
|
|
Loading…
Reference in New Issue