parent
6815f4e941
commit
c31accc52a
|
@ -48,9 +48,8 @@ CheckBufferOverrun instance;
|
||||||
|
|
||||||
void CheckBufferOverrun::arrayIndexOutOfBounds(const Token *tok, int size, int index)
|
void CheckBufferOverrun::arrayIndexOutOfBounds(const Token *tok, int size, int index)
|
||||||
{
|
{
|
||||||
if (size == 1)
|
if (size > 1)
|
||||||
return;
|
{
|
||||||
|
|
||||||
std::ostringstream errmsg;
|
std::ostringstream errmsg;
|
||||||
errmsg << "Array '";
|
errmsg << "Array '";
|
||||||
if (tok)
|
if (tok)
|
||||||
|
@ -60,6 +59,7 @@ void CheckBufferOverrun::arrayIndexOutOfBounds(const Token *tok, int size, int i
|
||||||
errmsg << "[" << size << "]' index " << index << " out of bounds";
|
errmsg << "[" << size << "]' index " << index << " out of bounds";
|
||||||
reportError(tok, Severity::error, "arrayIndexOutOfBounds", errmsg.str().c_str());
|
reportError(tok, Severity::error, "arrayIndexOutOfBounds", errmsg.str().c_str());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CheckBufferOverrun::arrayIndexOutOfBounds(const Token *tok, const ArrayInfo &arrayInfo, const std::vector<int> &index)
|
void CheckBufferOverrun::arrayIndexOutOfBounds(const Token *tok, const ArrayInfo &arrayInfo, const std::vector<int> &index)
|
||||||
{
|
{
|
||||||
|
@ -780,17 +780,6 @@ void CheckBufferOverrun::checkScope(const Token *tok, const ArrayInfo &arrayInfo
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// in case %var% is declared as a pointer
|
|
||||||
else if (Token::Match(tok, "%var% [ %num% ]"))
|
|
||||||
{
|
|
||||||
const int index = MathLib::toLongNumber(tok->strAt(2));
|
|
||||||
if (index < 0)
|
|
||||||
{
|
|
||||||
arrayIndexOutOfBounds(tok, index, index);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Loop..
|
// Loop..
|
||||||
else if (Token::simpleMatch(tok, "for ("))
|
else if (Token::simpleMatch(tok, "for ("))
|
||||||
{
|
{
|
||||||
|
|
|
@ -943,7 +943,8 @@ private:
|
||||||
" int *ip = &i[1];\n"
|
" int *ip = &i[1];\n"
|
||||||
" ip[-10] = 1;\n"
|
" ip[-10] = 1;\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:5]: (error) Array 'ip[-10]' index -10 out of bounds\n", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
TODO_ASSERT_EQUALS("[test.cpp:5]: (error) Array ip[-10] out of bounds\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void array_index_multidim()
|
void array_index_multidim()
|
||||||
|
@ -1118,6 +1119,14 @@ private:
|
||||||
" p[-1] = 0;\n"
|
" p[-1] = 0;\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
check("void foo()\n"
|
||||||
|
"{\n"
|
||||||
|
" char s[] = \"abc\";\n"
|
||||||
|
" char *p = s + strlen(s);\n"
|
||||||
|
" if (p[-1]);\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void array_index_for_decr()
|
void array_index_for_decr()
|
||||||
|
|
Loading…
Reference in New Issue