Skip to main content

IAR Embedded Workbench for Arm 9.70.x

CERT-EXP35-C

In this section:
Synopsis

Do not modify objects with temporary lifetime

Enabled by default

Yes

Severity/Certainty

Low/Medium

lowmedium.png
Full description

If a function call returns by value a struct or union containing an array, do not modify those arrays within the expression containing the function call. Do not access an array returned by a function after the next sequence point or after the evaluation of the containing full expression or full declarator ends.

Coding standards
CERT EXP35-C

Do not modify objects with temporary lifetime

Code examples

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

int printf(const char *a, ...);

struct my_struct { char str[8]; };

struct my_struct get_new_struct(void) {
    struct my_struct a = { "AAAAAAA" };
    return a;
}

void example(void) {
    printf("%s\n", get_new_struct().str);
}

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

int printf(const char *a, ...);

struct my_struct { char str[8]; };

struct my_struct get_new_struct(void) {
    struct my_struct a = { "AAAAAAA" };
    return a;
}

void example(void) {
    struct my_struct s = get_new_struct();
    printf("%s\n", s.str);
}