...
Implementations conforming to C are required to declare errno
in <errno.h>
, although some historic implementations failed to do so.
Noncompliant Code Example (malloc(), free())
In this noncompliant example, the identifiers for the C Standard Library functions malloc()
and free()
are reserved.
Code Block | ||||
---|---|---|---|---|
| ||||
void *malloc(size_t nbytes) { /* violation */
void *ptr;
/* ... */
/* allocate storage from own pool and set ptr */
return ptr;
}
void free(void *ptr) { /* violation */
/* ... */
/* return storage to own pool */
}
|
Compliant Solution ( malloc(), free()
)
This complaint example changes the names of the identfiers to malloc_custom()
and free_custom()
.
Code Block | ||||
---|---|---|---|---|
| ||||
void *malloc_custom(size_t nbytes) {
void *ptr;
/* ... */
/* allocate storage from own pool and set ptr */
return ptr;
}
void free_custom(void *ptr) {
/* ... */
/* return storage to own pool */
} |
Risk Assessment
Using reserved identifiers can lead to incorrect program operation.
...
CERT C++ Secure Coding Standard | DCL32-CPP. Do not declare or define a reserved identifier |
---|---|
ISO/IEC TS 17961 | Using identifiers that are reserved for the implementation [resident] |
Bibliography
[IEEE Std 1003.1-2008] | Section 2.2 "The Compilation Environment" |
---|---|
[ISO/IEC 9899:2011] | Section 7.1.3, "Reserved Identifiers" |
...