Array index out of bounds: prevent false positive when a dimension for an array is unknown
This commit is contained in:
parent
0186fc0650
commit
fd7e085c9d
|
@ -1093,6 +1093,10 @@ void CheckBufferOverrun::checkScope(const Token *tok, const ArrayInfo &arrayInfo
|
|||
totalElements *= arrayInfo.num(ri);
|
||||
}
|
||||
|
||||
// totalElements == 0 => Unknown size
|
||||
if (totalElements == 0)
|
||||
continue;
|
||||
|
||||
// just taking the address?
|
||||
const bool addr(Token::Match(tok->previous(), "[.&]") ||
|
||||
Token::simpleMatch(tok->tokAt(-2), "& ("));
|
||||
|
|
|
@ -1159,7 +1159,13 @@ private:
|
|||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:6]: (error) Array 'a[6][6][6]' index a[6][6][2] out of bounds\n", errout.str());
|
||||
|
||||
|
||||
// unknown dim..
|
||||
check("void f()\n"
|
||||
"{\n"
|
||||
" int a[2][countof(x)] = {{1,2},{3,4}};\n"
|
||||
" a[0][0] = 0;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void array_index_switch_in_for()
|
||||
|
|
Loading…
Reference in New Issue