Fixed #3490 (False positive: sscanf with %c)

This commit is contained in:
Daniel Marjamäki 2012-01-18 23:57:08 +01:00
parent 7607e4c68d
commit 525e7fba20
2 changed files with 11 additions and 1 deletions

View File

@ -1212,6 +1212,7 @@ void CheckOther::invalidScanf()
}
else if (std::isalpha(formatstr[i])) {
if (formatstr[i] != 'c') // #3490 - field width limits are not necessary for %c
invalidScanfError(tok);
format = false;
}

View File

@ -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"