Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Violation for rule 109
#1
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.


Thanks,
Klaus
<t></t>
Reply
#2
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.
Posted by and on behalf of the MISRA C Working Group
Reply
#3
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?
<t></t>
Reply
#4
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.
Posted by and on behalf of the MISRA C Working Group
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)