Incorrect comment in mc2_1703.c

Questions and discussions about the Exemplar Suite for MISRA-C:2004

Moderators: misra-c, david ward

Incorrect comment in mc2_1703.c

Postby Graham Andrews » Wed Sep 17, 2008 2:27 pm

There is a comment regarding line:
Code: Select all
else if ( ( &array_12 [ 12 ] - &array_12 [ index_1 ] ) > 0 )

The comment states that this line violates rule 17.4, which is not the case, as the variable array_12 has been declared as an array.
It should state that there is a violation of rule 21.1 regarding array bound errors.
Graham Andrews
Edinburgh Design Centre
Analog Devices Inc
Graham Andrews
 
Posts: 5
Joined: Fri Apr 20, 2007 10:43 am
Location: Edinburgh

Re: Incorrect comment in mc2_1703.c

Postby misra-c » Tue Jun 02, 2009 11:18 am

The array has 12 elements so it is valid to take the address of array_12[12] because the standard permits taking the address of the element one beyond the end of an array.

The code in the example file ensures that index_1 is in the range 0 to 11. Therefore, both array indices are valid at least for the purposes of taking addresses.

Rule 17.4 prohibits all pointer arithmetic including subtraction of pointers even if they point into the same array.
MISRA C Committee
misra-c
 
Posts: 159
Joined: Thu Jan 05, 2006 2:11 pm


Return to MISRA-C:2004 Exemplar Suite

Who is online

Users browsing this forum: No registered users and 1 guest

cron