#6050 arithmetic on void** - fix false positive
This commit is contained in:
parent
a52c122229
commit
66d767b4b5
|
@ -311,9 +311,9 @@ void CheckSizeof::sizeofVoid()
|
||||||
sizeofDereferencedVoidPointerError(tok, tok->strAt(3));
|
sizeofDereferencedVoidPointerError(tok, tok->strAt(3));
|
||||||
} else if (Token::Match(tok, "%var% +|-|++|--") ||
|
} else if (Token::Match(tok, "%var% +|-|++|--") ||
|
||||||
Token::Match(tok, "+|-|++|-- %var%")) { // Arithmetic operations on variable of type "void*"
|
Token::Match(tok, "+|-|++|-- %var%")) { // Arithmetic operations on variable of type "void*"
|
||||||
int index = (tok->isName()) ? 0 : 1;
|
const int index = (tok->isName()) ? 0 : 1;
|
||||||
const Variable* var = tok->tokAt(index)->variable();
|
const Variable* var = tok->tokAt(index)->variable();
|
||||||
if (var && Token::Match(var->typeStartToken(), "void * !!*")) {
|
if (var && !var->isArray() && Token::Match(var->typeStartToken(), "void * !!*")) {
|
||||||
std::string varname = tok->strAt(index);
|
std::string varname = tok->strAt(index);
|
||||||
// In case this 'void *' var is a member then go back to the main object
|
// In case this 'void *' var is a member then go back to the main object
|
||||||
const Token* tok2 = tok->tokAt(index);
|
const Token* tok2 = tok->tokAt(index);
|
||||||
|
|
|
@ -647,6 +647,11 @@ private:
|
||||||
" (foo[0]).data++;\n"
|
" (foo[0]).data++;\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:5]: (portability) '(foo[0]).data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:5]: (portability) '(foo[0]).data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined.\n", errout.str());
|
||||||
|
|
||||||
|
// #6050 arithmetic on void**
|
||||||
|
check("void* array[10];\n"
|
||||||
|
"void** b = array + 3;\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void customStrncat() {
|
void customStrncat() {
|
||||||
|
|
Loading…
Reference in New Issue