Menu

Incorrect va_list 'vl' used before va_start() was called.

2021-01-03
2021-10-08
  • Nick Andrews

    Nick Andrews - 2021-01-03

    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..)

     
  • CHR

    CHR - 2021-01-25

    I can't reproduce this in either C or C++ mode with v2.3.

     
  • Coldfirex

    Coldfirex - 2021-07-18

    We see this in v2.5.
    Here is a one example

     
  • xiang xia

    xiang xia - 2021-09-30

    Hi, I came across this problem too. I'm using cppcheck 2.6 built on Mac. Maybe it is a false positive??

     
  • CHR

    CHR - 2021-09-30

    Here's a reduced example from @coldfirex's post:

    #if __GNUC__ < 4
    #define va_copy     __va_copy
    #endif
    
    void SetTo(va_list _list)
    {
        va_list list;
        va_copy(list, _list);
        va_end(list);
    }
    

    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?

     
    • xiang xia

      xiang xia - 2021-10-08

      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>

      #pragma once
      #define _INC_STDARG
      
      #include <vcruntime.h>
      
      _CRT_BEGIN_C_HEADER
      
      #define va_start __crt_va_start
      #define va_arg   __crt_va_arg
      #define va_end   __crt_va_end
      #define va_copy(destination, source) ((destination) = (source))
      
      
      
      _CRT_END_C_HEADER
      
       

      Last edit: xiang xia 2021-10-08
  • xiang xia

    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?

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.