Fixed #3490 (False positive: sscanf with %c)
This commit is contained in:
parent
7607e4c68d
commit
525e7fba20
|
@ -1212,6 +1212,7 @@ void CheckOther::invalidScanf()
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (std::isalpha(formatstr[i])) {
|
else if (std::isalpha(formatstr[i])) {
|
||||||
|
if (formatstr[i] != 'c') // #3490 - field width limits are not necessary for %c
|
||||||
invalidScanfError(tok);
|
invalidScanfError(tok);
|
||||||
format = false;
|
format = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,6 +88,7 @@ private:
|
||||||
TEST_CASE(testScanf1);
|
TEST_CASE(testScanf1);
|
||||||
TEST_CASE(testScanf2);
|
TEST_CASE(testScanf2);
|
||||||
TEST_CASE(testScanf3);
|
TEST_CASE(testScanf3);
|
||||||
|
TEST_CASE(testScanf4);
|
||||||
|
|
||||||
TEST_CASE(testScanfArgument);
|
TEST_CASE(testScanfArgument);
|
||||||
TEST_CASE(testPrintfArgument);
|
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());
|
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() {
|
void testScanfArgument() {
|
||||||
check("void foo() {\n"
|
check("void foo() {\n"
|
||||||
" scanf(\"%1d\", &foo);\n"
|
" scanf(\"%1d\", &foo);\n"
|
||||||
|
|
Loading…
Reference in New Issue