diff --git a/lib/checkio.cpp b/lib/checkio.cpp index ee1b4e36c73..0e1d0395146 100644 --- a/lib/checkio.cpp +++ b/lib/checkio.cpp @@ -674,7 +674,6 @@ void CheckIO::checkFormatString(const Token * const tok, ++i; } if (scanf_s && !skip) { - numSecure++; if (argListTok) { argListTok = argListTok->nextArgument(); } @@ -722,7 +721,7 @@ void CheckIO::checkFormatString(const Token * const tok, if (!(argInfo.isArrayOrPointer() && argInfo.element && !argInfo.typeToken->isStandardType())) invalidScanfArgTypeError_s(tok, numFormat, specifier, &argInfo); } - if (scanf_s && argInfo.typeToken) { + if (scanf_s) { numSecure++; if (argListTok) { argListTok = argListTok->nextArgument(); diff --git a/test/testio.cpp b/test/testio.cpp index b402f5c0aa1..ec6a87a1e16 100644 --- a/test/testio.cpp +++ b/test/testio.cpp @@ -4800,6 +4800,13 @@ class TestIO : public TestFixture { " wscanf_s(L\"%4[^-]\", msStr1, _countof(msStr1));\n" "}\n", dinit(CheckOptions, $.platform = Platform::Type::Win32W)); ASSERT_EQUALS("", errout_str()); + + check("void f(const char* c) {\n" + " const size_t N = 5;\n" + " char buf[N];\n" + " sscanf_s(c, \"%4[^.]\", buf, N);\n" + "}\n", dinit(CheckOptions, $.platform = Platform::Type::Win64)); + ASSERT_EQUALS("", errout_str()); } void testQStringFormatArguments() {