Search code examples
misra

How to fix MISRA warning: MISRA 18.4 (C90-2012 adv.)


I have used one API in which it catched the address of the parameter in a formal arguement. But there was I used log and used that address for printing purposes in that I got the MISRA warning such as below as you can see:

MISRA.PTR.ARITH Pointer is used in arithmetic or array index expression

How do I fix this warning?

Code snippet (from comment):

int8u my_api(uint8_t *a1,uint8_t *a2,uint8_t *a3)
{
  printf(" DeviceMAC: %02x%02x%02x%02x%02x%02x%02x%02x",
      a1[0],a1[1],a1[2],a1[3],a1[4],a1[5],a1[6],a1[7] );
  return 0;
}

Solution

  • MISRA makes a difference between pointer and array types of a parameter. If you want to use array indices, your function header should look like

    int8u my_api(uint8_t a1[], uint8_t a2[], uint8_t a3[])