Menu

Format String Error Check Prioritization

2025-02-05
2025-02-05
  • yoosang.won

    yoosang.won - 2025-02-05

    In the header file, NEV_LOGD is defined as follows
    '#define NEV_LOGD(...) {(void)0;}

    In the cpp file, the target source file is like below:
    '#include <header.hpp>
    int main() {
    int test = 0;
    NEV_LOGD(DEBUG, "main start %u", test);
    }</header.hpp>

    Although NEV_LOGD is declared like this in the header file,
    NEV_LOGD(...) {(void)0;}

    I want to check for format errors in NEV_LOGD,
    but even with the following declaration in the library xml, no error occurs:
    <function name="NEV_LOGD">
    <formatstr type="printf">
    <arg nr="1">
    <formatstr>
    </formatstr></arg>
    </formatstr></function>

    If I remove the definition of NEV_LOGD from the header file, the check works.
    Is there any way to ensure that the file format declared in the library is always checked?

     

    Last edit: yoosang.won 2025-02-05
  • Andrew C Aitchison

    If you wrap the definition this this:

    #ifndef USE_NEV_LOG
    #define NEV_LOGD(...) {(void)0;}
    #endif
    

    cppcheck will consider the case where your define does not happen.

    You will need to use
    cppcheck --enable=style source.cpp
    to get the warning

    source.c:5:10: style: Variable 'test' is assigned a value that is never used. [unreadVariable]
    int test = 0;
                                ^
    
     

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.