BufferOverflow: Updated message for out of bounds array index or redundant condition
This commit is contained in:
parent
57d318b2e5
commit
3e23e243f6
|
@ -70,10 +70,15 @@ void CheckBufferOverrun::arrayIndexOutOfBoundsError(const Token *tok, const Arra
|
|||
errmsg << "Array '" << arrayInfo.varname() << "[" << arrayInfo.num(0)
|
||||
<< "]' accessed at index " << index.intvalue << ", which is out of bounds.";
|
||||
|
||||
if (index.condition)
|
||||
if (index.condition) {
|
||||
errmsg << " Otherwise condition '" << index.condition->expressionString() << "' is redundant.";
|
||||
|
||||
reportError(tok, Severity::error, "arrayIndexOutOfBounds", errmsg.str());
|
||||
std::list<const Token *> callstack;
|
||||
callstack.push_back(tok);
|
||||
callstack.push_back(index.condition);
|
||||
reportError(callstack, Severity::warning, "arrayIndexOutOfBoundsCond", errmsg.str());
|
||||
} else {
|
||||
reportError(tok, Severity::error, "arrayIndexOutOfBounds", errmsg.str());
|
||||
}
|
||||
}
|
||||
|
||||
void CheckBufferOverrun::arrayIndexOutOfBoundsError(const std::list<const Token *> &callstack, const ArrayInfo &arrayInfo, const std::vector<MathLib::bigint> &index)
|
||||
|
@ -1155,7 +1160,7 @@ void CheckBufferOverrun::checkScope(const Token *tok, const ArrayInfo &arrayInfo
|
|||
const std::list<ValueFlow::Value> &values = tok->next()->astOperand2()->values;
|
||||
std::list<ValueFlow::Value>::const_iterator it;
|
||||
for (it = values.begin(); it != values.end(); ++it) {
|
||||
if (it->intvalue >= arrayInfo.num()[0]) {
|
||||
if (it->intvalue >= arrayInfo.num()[0] && (_settings->isEnabled("warning") || !it->condition)) {
|
||||
arrayIndexOutOfBoundsError(tok, arrayInfo, *it);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2062,7 +2062,7 @@ private:
|
|||
" str[i] = 0;\n"
|
||||
" if (i==10) {}\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (error) Array 'str[3]' accessed at index 10, which is out of bounds. Otherwise condition 'i==10' is redundant.\n", errout.str());
|
||||
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (warning) Array 'str[3]' accessed at index 10, which is out of bounds. Otherwise condition 'i==10' is redundant.\n", errout.str());
|
||||
}
|
||||
|
||||
void buffer_overrun_1_standard_functions() {
|
||||
|
|
Loading…
Reference in New Issue