However in cppcheck (versions <= 2.4.1) the function is declared in std.cfg as a function returning a pointer.
This is in accordance with the C11 language standard (see e.g. https://en.cppreference.com/w/c/chrono/localtime),
but Microsoft's older compilers are still at C89 (the more recent ones partially implement some really useful stuff from C99 and C11). Is there a way to disable the checks for C11 functionality in cppcheck, so that the false positive for "localtime_s()" doesn't appear? I am afraid the option "--std=" doesn't help in this case, because the file "std.cfg" has no information regarding for which language standard version a particular function definition should be considered.
Currently I see only one possible solution, which could be included in a future version of cppcheck: adding the MS definition for this function (returning an "errno_t") as an override to a separate configuration file (something like "msc_crt.cfg") and use config file on command line to override declarations from a previous one (instead of having to use individual suppressions or generally suppressing all AssignmentAddressToInteger warnings, which would introduce the risk of overlooking some real problems in code):
cppcheck ... --library=std.cfg --library=msc_crt.cfg ... source.cpp
(NOTE: std.cfg is default anyway and can be omitted, here only for clarifying the precedence).
For such an approach the function definition for the microsoft variant of localtime_s() would then look like:
your configuration is more or less ok I think.. a small problem with adding your configuration is that it works almost "by accident". If we manage to specify the order explicitly somehow then I have no major complaints about it.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello there,
in MS Visual Studio 2005 and newer (up to and including VS 2019) localtime_s() is declared with errno_t as return type, see https://docs.microsoft.com/de-de/cpp/c-runtime-library/reference/localtime-s-localtime32-s-localtime64-s?view=msvc-160
However in cppcheck (versions <= 2.4.1) the function is declared in std.cfg as a function returning a pointer.
This is in accordance with the C11 language standard (see e.g. https://en.cppreference.com/w/c/chrono/localtime),
but Microsoft's older compilers are still at C89 (the more recent ones partially implement some really useful stuff from C99 and C11). Is there a way to disable the checks for C11 functionality in cppcheck, so that the false positive for "localtime_s()" doesn't appear? I am afraid the option "--std=" doesn't help in this case, because the file "std.cfg" has no information regarding for which language standard version a particular function definition should be considered.
Currently I see only one possible solution, which could be included in a future version of cppcheck: adding the MS definition for this function (returning an "errno_t") as an override to a separate configuration file (something like "msc_crt.cfg") and use config file on command line to override declarations from a previous one (instead of having to use individual suppressions or generally suppressing all AssignmentAddressToInteger warnings, which would introduce the risk of overlooking some real problems in code):
cppcheck ... --library=std.cfg --library=msc_crt.cfg ... source.cpp
(NOTE: std.cfg is default anyway and can be omitted, here only for clarifying the precedence).
For such an approach the function definition for the microsoft variant of localtime_s() would then look like:
<function name="localtime_s,std::localtime_s">
<returnvalue type="errno_t">
<noreturn>false</noreturn>
<leak-ignore>
<arg nr="1" direction="in">
<not-null>
</not-null></arg>
<arg nr="2" direction="out">
<not-null>
</not-null></arg>
</leak-ignore></returnvalue></function>
Otherwise I really like cppcheck!
Regards,
Martin
P.S.: If someone wants to try out such a declaration in a separate config file, see the attachment...
(it works for me with cppcheck 2.4)
Last edit: Martin Hohl 2021-04-13
ticket:
https://trac.cppcheck.net/ticket/8588
your configuration is more or less ok I think.. a small problem with adding your configuration is that it works almost "by accident". If we manage to specify the order explicitly somehow then I have no major complaints about it.