#6050 arithmetic on void** - fix false positive

This commit is contained in:
Alexander Mai 2014-08-17 19:14:55 +02:00
parent a52c122229
commit 66d767b4b5
2 changed files with 7 additions and 2 deletions

View File

@ -311,9 +311,9 @@ void CheckSizeof::sizeofVoid()
sizeofDereferencedVoidPointerError(tok, tok->strAt(3));
} else if (Token::Match(tok, "%var% +|-|++|--") ||
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();
if (var && Token::Match(var->typeStartToken(), "void * !!*")) {
if (var && !var->isArray() && Token::Match(var->typeStartToken(), "void * !!*")) {
std::string varname = tok->strAt(index);
// In case this 'void *' var is a member then go back to the main object
const Token* tok2 = tok->tokAt(index);

View File

@ -647,6 +647,11 @@ private:
" (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());
// #6050 arithmetic on void**
check("void* array[10];\n"
"void** b = array + 3;\n");
ASSERT_EQUALS("", errout.str());
}
void customStrncat() {