MISRA Discussion Forums
MISRA rule 17.4 violation ? - Printable Version

+- MISRA Discussion Forums (https://forum.misra.org.uk)
+-- Forum: MISRA C (https://forum.misra.org.uk/forumdisplay.php?fid=4)
+--- Forum: MISRA-C: 2004 rules (https://forum.misra.org.uk/forumdisplay.php?fid=17)
+---- Forum: 6.17 Pointers and Arrays (https://forum.misra.org.uk/forumdisplay.php?fid=44)
+---- Thread: MISRA rule 17.4 violation ? (/showthread.php?tid=876)



MISRA rule 17.4 violation ? - misterb - 26-01-2012

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


Re: MISRA rule 17.4 violation ? - misterb - 27-01-2012

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