Fixed #5129 (FP:arithOperationsOnVoidPointer on void**)
This commit is contained in:
parent
06c5bd0daa
commit
14787cde99
|
@ -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);
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue