From ca4e5ac52743ecd780d726a9658a6fb2e054c364 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Mon, 20 Dec 2021 17:22:39 +0100 Subject: [PATCH] Fix #7038 false negative for string argument in the CheckIO (#3649) --- lib/checkio.cpp | 2 ++ test/testio.cpp | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/lib/checkio.cpp b/lib/checkio.cpp index 02259b55d..ce2634bb1 100644 --- a/lib/checkio.cpp +++ b/lib/checkio.cpp @@ -1386,6 +1386,8 @@ CheckIO::ArgumentInfo::ArgumentInfo(const Token * arg, const Settings *settings, for (int p = 0; p < valuetype->pointer; p++) tempToken->insertToken("*"); tempToken = const_cast(typeToken); + if (top->isBinaryOp() && valuetype->pointer == 1 && (valuetype->type == ValueType::CHAR || valuetype->type == ValueType::WCHAR_T)) + tempToken->tokType(Token::eString); return; } } diff --git a/test/testio.cpp b/test/testio.cpp index 19a49e40a..fc013d883 100644 --- a/test/testio.cpp +++ b/test/testio.cpp @@ -2113,6 +2113,11 @@ private: ASSERT_EQUALS("[test.cpp:3]: (warning) %s in format string (no. 1) requires a 'char *' but the argument type is 'const char *'.\n" "[test.cpp:3]: (warning) scanf() without field width limits can crash with huge input data.\n", errout.str()); } + + check("void f() {\n" // #7038 + " scanf(\"%i\", \"abc\" + 1);\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:2]: (warning) %i in format string (no. 1) requires 'int *' but the argument type is 'const char *'.\n", errout.str()); } void testPrintfArgument() {