cppcheck 2.21.0 generates invalidPrintfArgType_float and wrongPrintfScanfArgNum for the following code:
#include <stdio.h> #include <locale.h> int main() { double value = 3.14; const size_t buffer_size = 64; char buffer[buffer_size]; int precision = 2; _locale_t locale = _create_locale(LC_ALL, "C"); _sprintf_s_l(buffer, buffer_size, "%.*f", locale, precision, value); _free_locale(locale); return 0; }
cppcheck.exe --library=windows --enable=all .
test\main.cpp:11:2: warning: %f in format string (no. 2) requires 'double' but the argument type is 'signed int'. [invalidPrintfArgType_float] _sprintf_s_l(buffer, buffer_size, "%.*f", locale, precision, value); ^ test\main.cpp:11:2: warning: _sprintf_s_l format string requires 2 parameters but 3 are given. [wrongPrintfScanfArgNum] _sprintf_s_l(buffer, buffer_size, "%.*f", locale, precision, value); ^
Same for _swprintf_s_l.
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/14899
Log in to post a comment.
cppcheck 2.21.0 generates invalidPrintfArgType_float and wrongPrintfScanfArgNum for the following code:
Same for _swprintf_s_l.
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/14899