[C-safe-secure-studygroup] MISRA C:2012 Rule 5.7 Undefined Behaviour in C90

Fulvio Baccaglini fulvio_baccaglini at programmingresearch.com
Wed Jun 21 16:13:11 UTC 2017


Hi,

Re:  Study Group Meeting Minutes - 20170614
>
> Actions from the meeting:
> - Fulvio to address the group concerning undefined behaviours and
> conformance to C90, in accordance with Rule 5.7

This is my personal interpretation of the undefined behaviour applicable
to Rule 5.7 "A tag name shall be a unique identifier".

>From the Example section of Rule 5.7:

~~~~~~~~>
struct elk
{
    uint16_t x;
};

struct elk     /* Non-compliant - declaration of different type
                * Constraint violation in C99 */
{
    uint32_t x;
};
<~~~~~~~~

The constraint violation in C99 would be due to:
[C99-6.7.2.3-1] Tags - Constraints - "A specific type shall have its
content defined at most once".

For C90 the corresponding section for Tags [C90-6.5.2.3] does not have a
"Constraints" section, however the "Semantics" section says:

~~~~~~~~>
A type specifier of the form

    struct-or-union    identifier    {    struct-declaration-list    }
or
    enum    identifier    {    enumerator-list    }

declares the identifier to be the tag of the structure, union, or
enumeration specified by the list. The list defines the structure
content, union content, or enumeration content. If this declaration of
the lag is visible, a subsequent declaration that uses the tag and that
omits the bracketed list specifies the declared structure, union, or
enumerated type. Subsequent declarations in the same scope shall omit
the bracketed list.
<~~~~~~~~

I think that the second declaration of "elk" would violate the "shall"
in "Subsequent declarations in the same scope shall omit the bracketed
list", so it would result in undefined behaviour.

Even considering the "shall" not applicable, the C90 standard does not
define how the inconsistency between the two "elk" declarations should
be handled, so I think that this would still result in undefined behaviour.

P.S. as we plan to only consider the latest version of the C standard,
this issue would not apply.

Fulvio
---------------------------------------------------------------------------------------
 This email has been scanned for email related threats and delivered safely by Mimecast.
 For more information please visit http://www.mimecast.com
---------------------------------------------------------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.trustable.io/pipermail/c-safe-secure-studygroup/attachments/20170621/5e0ec1d1/attachment.html>


More information about the C-safe-secure-studygroup mailing list