Menu

False positive (wrongPrintfScanfArgNum)

Nebiun
2023-01-04
2023-01-05
  • Nebiun

    Nebiun - 2023-01-04

    Hi, this is the problem.

    I define a macro like this:

    #define NIPQUAD(addr)  \
        ((unsigned char *)&addr)[0], ((unsigned char *)&addr)[1], ((unsigned char *)&addr)[2], ((unsigned char *)&addr)[3]
    

    And then I use the macro in printf:

    printf("ip = %u.%u.%u.%u\n", NIPQUAD(ip_rs));
    

    cppcheck show an ERROR like this:
    error wrongPrintfScanfArgNum "printf format string requires 4 parameters but only 1 are given"

     
  • CHR

    CHR - 2023-01-04

    Is the macro visible at the location of the printf() call?
    There is no FP for

    #define NIPQUAD(addr)  \
        ((unsigned char *)&addr)[0], ((unsigned char *)&addr)[1], ((unsigned char *)&addr)[2], ((unsigned char *)&addr)[3]
    void f(int ip_rs) {
        printf("ip = %u.%u.%u.%u\n", NIPQUAD(ip_rs));
    }
    
     
  • Nebiun

    Nebiun - 2023-01-04

    Macro is defined in an header file included by source file

     
  • Nebiun

    Nebiun - 2023-01-04

    strange behaviour: with a simple main and an header file cppcheck (windows) does not show errors. I must check my configuration.

     
  • Nebiun

    Nebiun - 2023-01-05

    Then:
    I confirm the problem with cppcheck version 2.7 on Linux (cppcheck-2.7-1.el7.x86_64) .
    Program compiles fine, but cppcheck seem does not resolve the macro.

     
  • Nebiun

    Nebiun - 2023-01-05

    Solved: is not a cppcheck problem!
    Some source directories are not compiled but are present in the source tree. cppcheck scan them and found errors.
    Sorry for this false alarm
    Thankyou

     

Log in to post a comment.