MISRA rule 17.4 violation ?

6.17 Pointers and Arrays

Moderators: misra-c, david ward

Post Reply
misterb
Posts: 4
Joined: Fri Sep 09, 2011 4:21 pm
Company: Müller-BBM AST GmbH

MISRA rule 17.4 violation ?

Post by misterb » Thu Jan 26, 2012 8:14 am

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: Select all

#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; i<data->len; 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

misterb
Posts: 4
Joined: Fri Sep 09, 2011 4:21 pm
Company: Müller-BBM AST GmbH

Re: MISRA rule 17.4 violation ?

Post by misterb » Fri Jan 27, 2012 8:28 am

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

Post Reply

Return to “6.17 Pointers and Arrays”