Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
MISRA rule 17.4 violation ?
#1
Hello,

my compiler find in the following code a MISRA violation 17.4 at the last view code lines. Is this correct? If yes, please tell me how to solve the above mentioned code. In my opinion there is no MISRA rule 17.4 violation.

Code:
#define BUF_LEN1     (512u)

/* this violates rule 8.7, but this is intentionaly. It is only a rule 17.4 example */
static uint32_t buf1[BUF_LEN1];
  
static struct TestStruct
{
  uint32_t *buf;
  uint32_t len;
} data1 = {NULL, 0u};

static void InitStruct(uint32_t _len, uint32_t _buf[]);
static void UseStruct(struct TestStruct * data);

int32_t main( void )
{
    
    InitStruct(BUF_LEN1, buf1);
    UseStruct(&data1);

    return 0;
}

static void InitStruct(uint32_t _len, uint32_t _buf[])
{
  data1.len = _len;
  data1.buf = _buf;
}

static void UseStruct(struct TestStruct * data)
{
  uint32_t i;
  
  for (i=0u; ilen; i++)
  {
    /* process data in any way ... */
    /* this code line causes a MISRA 17.4 violation error by the compiler */
    data->buf[i] = 1u;
  }
}

Many thanks in advance and best regards,

Michael
<t></t>
Reply
#2
Hi,

I made a mistake. The above mentioned code is definitely a violation of MISRA rule 17.4. The compiler is correct.

I'm sorry for the inconvenience.

Kind regards,

Michael
<t></t>
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)