From b77203a277c37ff008b9205636e0c47927316acb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 5 Oct 2015 19:59:15 +0200 Subject: [PATCH] CheckIO: Handle AST pointer type better --- lib/checkio.cpp | 14 ++++++++++++-- test/testio.cpp | 4 ++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/checkio.cpp b/lib/checkio.cpp index 8a256a59b..a0591bc4c 100644 --- a/lib/checkio.cpp +++ b/lib/checkio.cpp @@ -1368,9 +1368,17 @@ CheckIO::ArgumentInfo::ArgumentInfo(const Token * tok, const Settings *settings, // TODO: This is a bailout so that old code is used in simple cases. Remove the old code and always use the AST type. if (!Token::Match(tok, "&| %str%|%num%|%name% ,|)") && !Token::Match(tok, "%name% [|(|.|<|::|?")) { const ValueType *valuetype = tok->argumentType(); - if (valuetype && valuetype->type >= ValueType::Type::BOOL && !valuetype->pointer) { + if (valuetype && valuetype->type >= ValueType::Type::BOOL) { tempToken = new Token(0); - if (valuetype->type <= ValueType::INT) + if (valuetype->pointer == 0U && valuetype->type <= ValueType::INT) + tempToken->str("int"); + else if (valuetype->type == ValueType::BOOL) + tempToken->str("bool"); + else if (valuetype->type == ValueType::CHAR) + tempToken->str("char"); + else if (valuetype->type == ValueType::SHORT) + tempToken->str("short"); + else if (valuetype->type == ValueType::INT) tempToken->str("int"); else if (valuetype->type == ValueType::LONG) tempToken->str("long"); @@ -1387,6 +1395,8 @@ CheckIO::ArgumentInfo::ArgumentInfo(const Token * tok, const Settings *settings, else if (valuetype->sign == ValueType::Sign::SIGNED) tempToken->isSigned(true); } + for (unsigned int p = 0; p < valuetype->pointer; p++) + tempToken->insertToken("*"); typeToken = tempToken; return; } diff --git a/test/testio.cpp b/test/testio.cpp index 27fe24027..9c9f0a378 100644 --- a/test/testio.cpp +++ b/test/testio.cpp @@ -3736,6 +3736,10 @@ private: "}\n"); ASSERT_EQUALS("", errout.str()); + check("void test() {\n" + " printf(\"%i\", (short *)x);\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:2]: (warning) %i in format string (no. 1) requires 'int' but the argument type is 'short *'.\n", errout.str()); } };