Fixed #3282 (Invalid report that an array index is of type char.)
This commit is contained in:
parent
ed97b62610
commit
f092779a4d
|
@ -1762,6 +1762,10 @@ void CheckOther::checkCharVariable()
|
|||
if (tok->str() == "*")
|
||||
tok = tok->next();
|
||||
|
||||
const unsigned int varid = tok->varId();
|
||||
if (!varid)
|
||||
continue;
|
||||
|
||||
// Check usage of char variable..
|
||||
unsigned int indentlevel = 0;
|
||||
for (const Token *tok2 = tok->next(); tok2; tok2 = tok2->next()) {
|
||||
|
@ -1775,8 +1779,7 @@ void CheckOther::checkCharVariable()
|
|||
}
|
||||
|
||||
if (!isPointer) {
|
||||
std::string temp = "%var% [ " + tok->str() + " ]";
|
||||
if ((tok2->str() != ".") && Token::Match(tok2->next(), temp.c_str())) {
|
||||
if ((tok2->str() != ".") && Token::Match(tok2->next(), "%var% [ %varid% ]", varid)) {
|
||||
charArrayIndexError(tok2->next());
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -33,7 +33,8 @@ private:
|
|||
|
||||
|
||||
void run() {
|
||||
TEST_CASE(array_index);
|
||||
TEST_CASE(array_index_1);
|
||||
TEST_CASE(array_index_2);
|
||||
TEST_CASE(bitop1);
|
||||
TEST_CASE(bitop2);
|
||||
TEST_CASE(return1);
|
||||
|
@ -60,7 +61,7 @@ private:
|
|||
checkOther.checkCharVariable();
|
||||
}
|
||||
|
||||
void array_index() {
|
||||
void array_index_1() {
|
||||
check("void foo()\n"
|
||||
"{\n"
|
||||
" unsigned char ch = 0x80;\n"
|
||||
|
@ -95,6 +96,15 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void array_index_2() {
|
||||
// #3282 - False positive
|
||||
check("void foo(char i);\n"
|
||||
"void bar(int i) {\n"
|
||||
" const char *s = \"abcde\";\n"
|
||||
" foo(s[i]);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void bitop1() {
|
||||
check("void foo()\n"
|
||||
|
|
Loading…
Reference in New Issue