Fixed false positive #5187: arithOperationsOnVoidPointerError when referencing void*

This commit is contained in:
PKEuS 2014-04-27 12:15:01 +02:00
parent 866ab1ce14
commit ecec4b0b46
2 changed files with 9 additions and 0 deletions

View File

@ -317,6 +317,8 @@ void CheckSizeof::sizeofVoid()
// Check for cast expression
if (Token::simpleMatch(tok2->previous(), ")") && !Token::Match(tok2->previous()->link(), "( const| void *"))
continue;
if (tok2->strAt(-1) == "&") // Check for reference operator
continue;
}
arithOperationsOnVoidPointerError(tok, varname,
var->typeStartToken()->stringifyList(var->typeEndToken()->next()));

View File

@ -526,6 +526,13 @@ 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* p = malloc(10);\n"
" int* p2 = &p + 4;\n"
" int* p3 = &p - 1;\n"
"}");
ASSERT_EQUALS("", errout.str());
check("void f() {\n"
" void** p1 = malloc(10);\n"
" p1--;\n"