Menu

Suppression inside of a macro

2020-10-13
2020-10-14
  • Adrian Reber

    Adrian Reber - 2020-10-13

    In the project I am using cppcheck for (CRIU) we have a macro which cppcheck does not like. The clang analyzer also complains about it:

    See: https://github.com/checkpoint-restore/criu/blob/criu-dev/include/common/bug.h

    #ifndef __clang_analyzer__
    # ifndef pr_err
    #  error pr_err macro must be defined
    # endif
    # define BUG_ON_HANDLER(condition)                          \
        do {                                        \
            if ((condition)) {                          \
                pr_err("BUG at %s:%d\n", __FILE__, __LINE__);           \
                __raise();                          \
                *(volatile unsigned long *)NULL = 0xdead0000 + __LINE__;    \
            }                                   \
        } while (0)
    #else
    # define BUG_ON_HANDLER(condition)  \
        do {                \
            assert(!condition); \
        } while (0)
    #endif
    

    I am able to disable the clang analyzer with an '#ifdef' and I was trying to put in
    a line to suppress cppcheck in the macro: /* cppcheck-suppress nullPointer */

    But it seems I can only disable the nullPointer warning if I put the suppress line before calling the macro.

    Is it possible to tell cppcheck to skip the nullPointer check just for this macro using inline annotations? That way I only have to add the annotation once.

    Thanks

     
  • Daniel Marjamäki

    It would be really nice to be able to put a suppression inside a macro. But that is not possible right now. And I have the feeling it would be a pretty complex change.

    This could be solved with a -D__clang_analyzer__ on the command line. I would combine that with a --force.

     
  • Adrian Reber

    Adrian Reber - 2020-10-14

    Okay, thanks. Will try using -D.

     

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.