Page 1 of 1

Violation for rule 109

Posted: Tue Sep 07, 2010 3:57 pm
by klaus83
Hello everybody,

Does anybody know if rule 109: "Overlapping storage shall not be used" is violated by having two pointer variables pointing on the same address??
My automated MISRA checker only looks for union declarations and definitions when checking this rule.


Re: Violation for rule 109

Posted: Tue Sep 14, 2010 4:41 pm
by misra-c
The MISRA C Rule you refer to is from the 1998 version. It was replaced in 2004 by a new version, MISRA C2, and this is the only version that should be used for new projects.

The original Rule 109 has been split into two rules in MISRA C2, rules 18.2 and 18.3 so the answer will be given in relation to these rules. Rule 18.2 requires that objects are not assigned to overlapping objects and Rule 18.3 requires that an area of memory isn't used for unrelated purposes.

The existence of two pointers that point to the same address does not in itself violate either of the MISRA C2 rules. If the pointers are used to copy an object to an overlapping object then the rule is violated. Similarly if the pointers are used to access the memory for completely different purposes, the rule is violated although it is difficult for a tool to be able to check this case.

Re: Violation for rule 109

Posted: Mon Dec 20, 2010 9:42 am
by armand
May I ask for some more details about rule 18.2: what precisely does the word "assign" include? Is it memory copy functions such as memcpy, memmove, memccpy, strcpy, strncpy, bcopy ? Does it also deal with standard assignments within unions? Any other operations?

Re: Violation for rule 109

Posted: Tue Jan 11, 2011 11:55 am
by misra-c
Rule 18.2 references two undefined behaviours that are described in the C90 standard. Undefined 34 relates to assignment of overlapping objects. Undefined 55 relates to copying memory using library functions other than memmove (this function is designed to permit overlapping memory areas to be copied). The rule therefore covers both assignment and copying using library functions.

The standard defines assignment between overlapping objects only when both objects overlap exactly and have the compatible types, ignoring type qualifiers. Therefore, assigning one member of a union to another member of the same union would seem to be well defined and is therefore permitted by Rule 18.2, although unions are not permitted by Rule 18.4.