Fixed #4965 (sizeof(void) check - error in message)

This commit is contained in:
Lucas Manuel Rodriguez 2013-08-20 06:20:52 +02:00 committed by Daniel Marjamäki
parent 707dfb4eea
commit 14d3886e19
2 changed files with 4 additions and 2 deletions

View File

@ -298,7 +298,7 @@ void CheckSizeof::sizeofVoid()
int index = (tok->isName()) ? 0 : 1; int index = (tok->isName()) ? 0 : 1;
const Variable* var = tok->tokAt(index)->variable(); 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->str(); std::string varname = tok->strAt(index);
// In case this 'void *' var is a member then go back to the main object // In case this 'void *' var is a member then go back to the main object
const Token* tok2 = tok->tokAt(index); const Token* tok2 = tok->tokAt(index);
if (index == 0) { if (index == 0) {

View File

@ -551,8 +551,10 @@ private:
check("void f(void *data) {\n" check("void f(void *data) {\n"
" unsigned char* c = (unsigned char *)data++;\n" " unsigned char* c = (unsigned char *)data++;\n"
" unsigned char* c2 = (unsigned char *)++data;\n"
"}"); "}");
ASSERT_EQUALS("[test.cpp:2]: (portability) 'data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined.\n", errout.str()); ASSERT_EQUALS("[test.cpp:2]: (portability) 'data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined.\n"
"[test.cpp:3]: (portability) 'data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined.\n", errout.str());
check("void f(void *data) {\n" check("void f(void *data) {\n"
" void* data2 = (void *)data + 1;\n" " void* data2 = (void *)data + 1;\n"