From 525e7fba20c8c174c3daebd5a09fdf1530bb4c75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 18 Jan 2012 23:57:08 +0100 Subject: [PATCH] Fixed #3490 (False positive: sscanf with %c) --- lib/checkother.cpp | 3 ++- test/testother.cpp | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 7e3c8a0f3..ff04e2fc9 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1212,7 +1212,8 @@ void CheckOther::invalidScanf() } else if (std::isalpha(formatstr[i])) { - invalidScanfError(tok); + if (formatstr[i] != 'c') // #3490 - field width limits are not necessary for %c + invalidScanfError(tok); format = false; } } diff --git a/test/testother.cpp b/test/testother.cpp index 4ce046bf6..357f305a7 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -88,6 +88,7 @@ private: TEST_CASE(testScanf1); TEST_CASE(testScanf2); TEST_CASE(testScanf3); + TEST_CASE(testScanf4); TEST_CASE(testScanfArgument); TEST_CASE(testPrintfArgument); @@ -2075,6 +2076,14 @@ private: ASSERT_EQUALS("[test.cpp:7]: (warning) fscanf format string has 0 parameters but 1 are given\n", errout.str()); } + void testScanf4() { + check("void f() {\n" + " char c;\n" + " scanf(\"%c\", &c);\n" + "}"); + ASSERT_EQUALS("", errout.str()); + } + void testScanfArgument() { check("void foo() {\n" " scanf(\"%1d\", &foo);\n"