Menu

report error "invalidPrintfArgType_unit" with cppcheck v2.8

DarrenSong
2022-07-12
2022-07-13
  • DarrenSong

    DarrenSong - 2022-07-12

    it confused me.
    the code is like below, the format string type is same as argument type, but still report this error.

    %lu in format string (no. 3) requires 'unsigned long' but the argument type is 'std::size_t {aka unsigned long}

     snprintf((char *)ev.data, MaxLogLength, "%6d:%6d:%5lu;%5s;%-16s;%s", \
       getpid(), gettid(), mq ? mq->getnumber() : 0, level, from, msgstr.c_str());
    

    the definition of function of getnumber() is below, my PC OS is 64 bit Debian9.

    std::size_t GCEventContext_MQ::getnumber()
    {
      return m_mq->get_num_msg();
    }
    
     
  • CHR

    CHR - 2022-07-12

    The portable format specifier for size_t is %zu.

     
    • DarrenSong

      DarrenSong - 2022-07-13

      Thank you very much

       

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.