Skip to main content

IAR Embedded Workbench for RISC-V 3.40

CERT-EXP36-C_b

In this section:
Synopsis

Do not cast pointers into more strictly aligned pointer types.

Enabled by default

Yes

Severity/Certainty

Low/Medium

lowmedium.png
Full description

Do not convert a pointer value to a pointer type that is more strictly aligned than the referenced type. Different alignments are possible for different types of objects. If the type-checking system is overridden by an explicit cast or the pointer is converted to a void pointer (void *) and then to a different type, the alignment of an object may be changed. This check is identical to MISRAC2012-Rule-11.5.

Coding standards
CERT EXP36-C

Do not convert pointers into more strictly aligned pointer types

MISRA C:2012 Rule-11.5

(Advisory) A conversion should not be performed from pointer to void into pointer to object

Code examples

The following code example fails the check and will give a warning:

int *loop_function(void *v_pointer) {
    /* ... */
    return v_pointer;
}

void func(char *char_ptr) {
    int *int_ptr = loop_function(char_ptr);

    /* ... */
}

The following code example passes the check and will not give a warning about this issue:

int *loop_function(int *v_pointer) {
    /* ... */
    return v_pointer;
}

void func(int *loop_ptr) {
    int *int_ptr = loop_function(loop_ptr);

    /* ... */
}