buffer overflow: clean up old checking for negative index
This commit is contained in:
parent
019d4491fb
commit
87daf5783e
|
@ -2038,26 +2038,6 @@ void CheckBufferOverrun::negativeIndexError(const Token *tok, MathLib::bigint in
|
|||
reportError(tok, Severity::error, "negativeIndex", ostr.str());
|
||||
}
|
||||
|
||||
void CheckBufferOverrun::negativeIndex()
|
||||
{
|
||||
const char pattern[] = "[ %num% ]";
|
||||
for (const Token *tok = Token::findmatch(_tokenizer->tokens(), pattern); tok; tok = Token::findmatch(tok->next(),pattern)) {
|
||||
const MathLib::bigint index = MathLib::toLongNumber(tok->next()->str());
|
||||
if (index < 0) {
|
||||
// Negative index. Check if it's an array.
|
||||
const Token *tok2 = tok;
|
||||
while (tok2->strAt(-1) == "]")
|
||||
tok2 = tok2->previous()->link();
|
||||
|
||||
if (tok2->previous() && tok2->previous()->varId()) {
|
||||
const Variable *var = tok2->previous()->variable();
|
||||
if (var && var->isArray())
|
||||
negativeIndexError(tok, index);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CheckBufferOverrun::ArrayInfo::ArrayInfo()
|
||||
: _element_size(0), _declarationId(0)
|
||||
{
|
||||
|
|
|
@ -62,7 +62,6 @@ public:
|
|||
void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) {
|
||||
CheckBufferOverrun checkBufferOverrun(tokenizer, settings, errorLogger);
|
||||
checkBufferOverrun.bufferOverrun();
|
||||
checkBufferOverrun.negativeIndex();
|
||||
checkBufferOverrun.arrayIndexThenCheck();
|
||||
checkBufferOverrun.writeOutsideBufferSize();
|
||||
}
|
||||
|
|
|
@ -67,7 +67,6 @@ private:
|
|||
// Check for buffer overruns..
|
||||
CheckBufferOverrun checkBufferOverrun(&tokenizer, &settings, this);
|
||||
checkBufferOverrun.bufferOverrun();
|
||||
checkBufferOverrun.negativeIndex();
|
||||
checkBufferOverrun.arrayIndexThenCheck();
|
||||
checkBufferOverrun.writeOutsideBufferSize();
|
||||
}
|
||||
|
@ -1759,8 +1758,7 @@ private:
|
|||
" TEST test;\n"
|
||||
" test.a[-1] = 3;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (error) Array 'test.a[10]' accessed at index -1, which is out of bounds.\n"
|
||||
"[test.cpp:4]: (error) Array index -1 is out of bounds.\n", errout.str());
|
||||
ASSERT_EQUALS("[test.cpp:4]: (error) Array 'test.a[10]' accessed at index -1, which is out of bounds.\n", errout.str());
|
||||
}
|
||||
|
||||
void array_index_for_decr() {
|
||||
|
|
Loading…
Reference in New Issue