The C11 Standard The C11 Standard [ISO/IEC 9899:2011] introduced a new term: temporary lifetime. Modifying . This term still remains in the C23 Standard. Modifying an object with temporary lifetime is is undefined behavior. According to subclause to subclause 6.2.4, paragraph 8 [ISO/IEC 9899:2024]
A non-lvalue expression with structure or union type, where the structure or union contains a member with array type (including, recursively, members of all contained structures and unions) refers to an object with automatic storage duration and temporary lifetime. Its lifetime begins when the expression is evaluated and its initial value is the value of the expression. Its lifetime ends when the evaluation of the containing full expression or full declarator ends. Any attempt to modify an object with temporary lifetime results in undefined behavior.
This definition differs from the C99 Standard (which defines modifying the result of a function call or accessing it after the next sequence point as undefined behavior) because a temporary object's lifetime ends when the evaluation containing the full expression or full declarator ends, so the result of a function call can be accessed. This extension to the lifetime of a temporary also removes a quiet change to C90 and improves compatibility with C++.
...
This noncompliant code example conforms to the C11 Standard; however, it fails to conform to C99. If compiled with a C99-conforming implementation, this code has undefined behavior 34 because the sequence point preceding the call to printf() comes between the call and the access by printf() of the string in the returned object.
...
Attempting to modify an array or access it after its lifetime expires may result in erroneous program behavior.
Rule | Severity | Likelihood | Detectable | Remediation CostRepairable | Priority | Level |
|---|---|---|---|---|---|---|
EXP35-C | Low | Probable | Yes | YesMedium | P4 P6 | L3 L2 |
Automated Detection
Tool | Version | Checker | Description | ||||||
|---|---|---|---|---|---|---|---|---|---|
| Astrée |
| temporary-object-modification | Partially checked | ||||||
| Axivion Bauhaus Suite |
| CertC-EXP35 | |||||||
| CodeSonar |
| LANG.CAST.ARRAY.TEMP | Array to Pointer Conversion on Temporary Object | ||||||
| Cppcheck Premium |
| premium-cert-exp35-c | |||||||
| Helix QAC |
| C0450, C0455, C0459, C0464, C0465 C++3807, C++3808 | Fully implemented | ||||||
| LDRA tool suite |
| 642 S, 42 D, 77 D | Enhanced Enforcement | ||||||
| Parasoft C/C++test |
| CERT_C-EXP35-a | Do not modify objects with temporary lifetime | ||||||
| CERT-C: Rule EXP35-C | Checks for accesses on objects with temporary lifetime (rule fully covered) | |||||||
| Splint |
| ||||||||
| RuleChecker |
| temporary-object-modification | Partially checked |
...
Bibliography
| [ISO/IEC 9899:20112024] | 6.2.4, "Storage Durations of Objects" |
...