2

I'm linting below code snippet at online demonstration website of PC-Lint with enabled MISRA 2004 checkings

    #include <stdint.h>

    //enable some of MISRA 2004 Rules
    //lint +e960
    
    static uint8_t printf_(uint8_t a, void * b, ...);
    static uint8_t printf_(uint8_t a, void * b, ...)
    {
      (void) a;
      (void) b;
      return 0U;
    }
    
    static const uint8_t (*func)(uint8_t a, void * b, ...) = printf_;
    
    int main(void)
    {
      uint8_t data[8U] = {0};
      (void) func(1U, &data[0], 2U);
      return 0;
    }

PC Lint then tells me that I have following violations of MISRA 2004 Rules:

Note 960: Violates MISRA 2004 Required Rule 16.1, function has variable number of arguments: printf_

Note 960: Violates MISRA 2004 Required Rule 16.9, function identifier used without '&' or parenthesized parameter list: printf_

How to suppress only MISRA 2004 Rule 16.1 for function printf_?
Until now I've tried following solutions, none of below work for me:

  • -esym(960, 16.1) suppresses MISRA Rule 16.1 for all other symbols
  • -estring(960, "printf_") suppresses all other MISRA Rules for printf_ symbol e.g. Rule 16.9
  • -estring(960, "function has variable number of arguments: 'printf_'") according to manual suppose to work, but I cannot make it happen
  • -estring(960, "function has variable number of arguments:", "printf_") some experimental hint from following website Matthias Kraaz' blog also doesn't work

The best which I got for now is:

  • putting printf_ in block of -esym(960, 16.1) ... +esym(960, 16.1), this however elevates MISRA 2004 warnings to the error level and stops compilation if another violation is going to happen.

I'm looking forward for your ideas.

Community
  • 1
  • 1
Lazureus
  • 462
  • 4
  • 19

0 Answers0