Fixed false positive #5187: arithOperationsOnVoidPointerError when referencing void*
This commit is contained in:
parent
866ab1ce14
commit
ecec4b0b46
|
@ -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()));
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue