Menu

Suppression by variable name not working

2020-07-09
2020-07-11
  • Simon Large

    Simon Large - 2020-07-09

    In my embedded application I an EEPROM which starts at address 0. To make access easier I create a mapping structure and then map this to address zero. Unsurprisingly cppcheck flags all accesses as nullPointer, which is expected.
    #define EEprom (*((EEprom_t *) 0)) Version = eeprom_read_byte(&EEprom.EE_Version);

    I tried to suppress these errors in the GUI client by adding a suppression which specifies error Id nullPointer and variable EEprom. Unfortunately it doesn't suppress anything.

    If I remove the variable name from the suppression definition then the supress works, but of course it's dangerous to suppress all nullPointer errors.

    Is this a bug or am I doing something wrong?

     
  • Daniel Marjamäki

    Thanks!

    hmm.. there is no variable here. It warns about the expression: (EEprom_t*)0. Not sure .. maybe it's ok to set that as variable name.

    A workaround could be:

    #ifdef __cppcheck__
    #define EEprom (*((EEprom_t *) 0x10000))
    #else
    #define EEprom (*((EEprom_t *) 0))
    #endif
    

    And define __cppcheck__ in the Cppcheck analysis.

     
  • Simon Large

    Simon Large - 2020-07-11

    Thanks! Yes, agreed, it's an edge case so I'm happy to use the workaround.

     
  • Daniel Marjamäki

    Or:

    #ifdef __cppcheck__
    EEprom_t EEprom = {123..};
    #else
    #define EEprom (*((EEprom_t *) 0))
    #endif
    

    Anyway.. I think it would be good to have the option to write a suppression comment for a macro:

    #define EEprom (*((EEprom_t *) 0)) // cppcheck-suppress nullPointer
    

    I have created this ticket for that: https://trac.cppcheck.net/ticket/9800

     

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.