Format
This commit is contained in:
parent
04c85baf03
commit
7754449fd6
|
@ -89,19 +89,20 @@ void CheckStl::outOfBounds()
|
||||||
const Token* indexTok = parent->tokAt(2)->astOperand2();
|
const Token* indexTok = parent->tokAt(2)->astOperand2();
|
||||||
if (!indexTok)
|
if (!indexTok)
|
||||||
continue;
|
continue;
|
||||||
const ValueFlow::Value *indexValue = indexTok ? indexTok->getMaxValue(false) : nullptr;
|
const ValueFlow::Value* indexValue = indexTok ? indexTok->getMaxValue(false) : nullptr;
|
||||||
if (indexValue && indexValue->intvalue >= value.intvalue) {
|
if (indexValue && indexValue->intvalue >= value.intvalue) {
|
||||||
outOfBoundsError(parent, tok->expressionString(), &value, indexTok->expressionString(), indexValue);
|
outOfBoundsError(
|
||||||
|
parent, tok->expressionString(), &value, indexTok->expressionString(), indexValue);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (mSettings->isEnabled(Settings::WARNING)) {
|
if (mSettings->isEnabled(Settings::WARNING)) {
|
||||||
indexValue = indexTok ? indexTok->getMaxValue(true) : nullptr;
|
indexValue = indexTok ? indexTok->getMaxValue(true) : nullptr;
|
||||||
if (indexValue && indexValue->intvalue >= value.intvalue) {
|
if (indexValue && indexValue->intvalue >= value.intvalue) {
|
||||||
outOfBoundsError(parent, tok->expressionString(), &value, indexTok->expressionString(), indexValue);
|
outOfBoundsError(
|
||||||
|
parent, tok->expressionString(), &value, indexTok->expressionString(), indexValue);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if (Token::Match(tok, "%name% . %name% (") && container->getYield(tok->strAt(2)) == Library::Container::Yield::START_ITERATOR) {
|
if (Token::Match(tok, "%name% . %name% (") && container->getYield(tok->strAt(2)) == Library::Container::Yield::START_ITERATOR) {
|
||||||
const Token *fparent = tok->tokAt(3)->astParent();
|
const Token *fparent = tok->tokAt(3)->astParent();
|
||||||
|
|
|
@ -352,15 +352,19 @@ private:
|
||||||
" std::vector<int> v;\n"
|
" std::vector<int> v;\n"
|
||||||
" if(v.at(b?42:0)) {}\n"
|
" if(v.at(b?42:0)) {}\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("test.cpp:3:error:Out of bounds access in expression 'v.at(b?42:0)' because 'v' is empty and 'at' may be non-zero.\n", errout.str());
|
ASSERT_EQUALS(
|
||||||
|
"test.cpp:3:error:Out of bounds access in expression 'v.at(b?42:0)' because 'v' is empty and 'at' may be non-zero.\n",
|
||||||
|
errout.str());
|
||||||
|
|
||||||
checkNormal("void f(std::vector<int> v, bool b){\n"
|
checkNormal("void f(std::vector<int> v, bool b){\n"
|
||||||
" if (v.size() == 1)\n"
|
" if (v.size() == 1)\n"
|
||||||
" if(v.at(b?42:0)) {}\n"
|
" if(v.at(b?42:0)) {}\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("test.cpp:3:warning:Either the condition 'v.size()==1' is redundant or v size can be 1. Expression 'v.at' cause access out of bounds.\n"
|
ASSERT_EQUALS(
|
||||||
|
"test.cpp:3:warning:Either the condition 'v.size()==1' is redundant or v size can be 1. Expression 'v.at' cause access out of bounds.\n"
|
||||||
"test.cpp:2:note:condition 'v.size()==1'\n"
|
"test.cpp:2:note:condition 'v.size()==1'\n"
|
||||||
"test.cpp:3:note:Access out of bounds\n", errout.str());
|
"test.cpp:3:note:Access out of bounds\n",
|
||||||
|
errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void outOfBoundsIndexExpression() {
|
void outOfBoundsIndexExpression() {
|
||||||
|
|
Loading…
Reference in New Issue