Fixed #5129 (FP:arithOperationsOnVoidPointer on void**)

This commit is contained in:
Alexander Mai 2013-10-31 06:04:51 +01:00 committed by Daniel Marjamäki
parent 06c5bd0daa
commit 14787cde99
2 changed files with 7 additions and 1 deletions

View File

@ -297,7 +297,7 @@ void CheckSizeof::sizeofVoid()
Token::Match(tok, "+|-|++|-- %var%")) { // Arithmetic operations on variable of type "void*"
int index = (tok->isName()) ? 0 : 1;
const Variable* var = tok->tokAt(index)->variable();
if (var && Token::Match(var->typeStartToken(), "void *")) {
if (var && 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

@ -520,6 +520,12 @@ private:
ASSERT_EQUALS("[test.cpp:4]: (portability) 'p1' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined.\n"
"[test.cpp:5]: (portability) 'p2' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined.\n", errout.str());
check("void f() {\n"
" void** p1 = malloc(10);\n"
" p1--;\n"
"}");
ASSERT_EQUALS("", errout.str());
check("void f() {\n"
" void** p1;\n"
" int j = sizeof(*p1);\n"