Menu

I have found a false positive deffect in cppcheck

2019-07-20
2021-01-05
  • Jaroslav Fojtik

    Jaroslav Fojtik - 2019-07-20

    Dears,

    size = vsprintf(NULL, format, paramList);
    is not NULL dereference but standard way how to get final string size.


    #include <stdarg.h>
    #include <stdio.h>
    int string::printf(const char* format, ...)
    {
      va_list paramList;
      va_start(paramList, format);
    #ifdef _HAVE_VSNPRINTF
      size = vsnprintf(0, 0, format, paramList);
    #else
      size = vsprintf(NULL, format, paramList);
    #endif
    
      if(size)
        {
        resize(size);
    #ifdef _HAVE_VSNPRINTF
        size = vsnprintf(ch, maxlen, format, paramList);
    #else
        size = vsprintf(ch, format, paramList);
    #endif
        }
      else
        erase();
    
      va_end(paramList);
      return size;
    }
    

    Jara

     

    Last edit: Daniel Marjamäki 2021-01-05
  • Daniel Marjamäki

    sorry for late reply. I fail to reproduce with latest cppcheck. If you still see this false positive then please feel free to ping..

     

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.