We have the following code that is incorrectly flagged -:
void foo(int bar, va_list ap)
{
va_list ap2;
va_copy(ap2, ap);
// Do something here with ap2...
va_end(ap2);
}
It reports ap2 is used at va_end(ap2) before va_start(), however va_start
is not necessary with va_copy because it explicitly initialises the va_list
(and is documented to do so..)
The error depends on __GNUC__, which is not part of gnu.cfg. One workaround is to run cppcheck with -D__GNUC__=4. @agassy: Is your code similar to this?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thank you for reply. My code is similar to your example while I'm using cppcheck in visual studio. In <stdargs.h> from MSVC include files, the macro definitions are as below. Any remedies I can use here?</stdargs.h>
Well, I fixed this problem by using "-Uva_copy". Not so graceful, though.
I just wonder when I specify my project using "--project" option, how can I configure to skip the system include files and using the *.cfg libs?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
We have the following code that is incorrectly flagged -:
void foo(int bar, va_list ap)
{
va_list ap2;
va_copy(ap2, ap);
// Do something here with ap2...
va_end(ap2);
}
It reports ap2 is used at va_end(ap2) before va_start(), however va_start
is not necessary with va_copy because it explicitly initialises the va_list
(and is documented to do so..)
I can't reproduce this in either C or C++ mode with v2.3.
We see this in v2.5.
Here is a one example
Hi, I came across this problem too. I'm using cppcheck 2.6 built on Mac. Maybe it is a false positive??
Here's a reduced example from @coldfirex's post:
The error depends on
__GNUC__
, which is not part of gnu.cfg. One workaround is to run cppcheck with-D__GNUC__=4
.@agassy: Is your code similar to this?
Thank you for reply. My code is similar to your example while I'm using cppcheck in visual studio. In <stdargs.h> from MSVC include files, the macro definitions are as below. Any remedies I can use here?</stdargs.h>
Last edit: xiang xia 2021-10-08
Well, I fixed this problem by using "-Uva_copy". Not so graceful, though.
I just wonder when I specify my project using "--project" option, how can I configure to skip the system include files and using the *.cfg libs?