From 14d3886e191fd4a3f1fb7d2d9cf7f071cb85288d Mon Sep 17 00:00:00 2001 From: Lucas Manuel Rodriguez Date: Tue, 20 Aug 2013 06:20:52 +0200 Subject: [PATCH] Fixed #4965 (sizeof(void) check - error in message) --- lib/checksizeof.cpp | 2 +- test/testsizeof.cpp | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/checksizeof.cpp b/lib/checksizeof.cpp index ac33b9a59..16bbb563c 100644 --- a/lib/checksizeof.cpp +++ b/lib/checksizeof.cpp @@ -298,7 +298,7 @@ void CheckSizeof::sizeofVoid() int index = (tok->isName()) ? 0 : 1; const Variable* var = tok->tokAt(index)->variable(); 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 const Token* tok2 = tok->tokAt(index); if (index == 0) { diff --git a/test/testsizeof.cpp b/test/testsizeof.cpp index 8e8da7355..dc4c9b745 100644 --- a/test/testsizeof.cpp +++ b/test/testsizeof.cpp @@ -551,8 +551,10 @@ private: check("void f(void *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" " void* data2 = (void *)data + 1;\n"