...
Some C implementations do not issue a diagnostic for the violation of this constraint. These noncompliant C translators continue to treat such declarations as implying the type int.
Compliant
...
Solution (Implicit int)
This compliant solution explicitly includes a type specifier:
...
If a function declaration is not visible at the point at which a call to the function is made, C90-compliant platforms assume an implicit declaration of
extern int funcidentifier();
This implies that the function may take any number and type of arguments and returns a single int.
...
| Code Block | ||||
|---|---|---|---|---|
| ||||
/* #include <stdlib.h> is missing */
int main(void) {
for (size_t i;
for (i = 0; i < 100; ++i) {
/* int malloc() assumed */
char *ptr = (char *)malloc(0x10000000); /* int malloc() assumed */
*ptr = 'a';
}
return 0;
}
|
When compiled with Microsoft Visual Studio (a C90-only platform) for a 64-bit platform, this noncompliant code example will eventually cause an access violation when dereferencing ptr in the loop.
...
| Code Block | ||||
|---|---|---|---|---|
| ||||
#include <stdlib.h>
int main(void) {
for (size_t i;
for (i = 0; i < 100; ++i) {
char *ptr = (char *)malloc(0x10000000); /* int malloc() assumed */
*ptr = 'a';
}
return 0;
} |
...
Do not declare a function with implicit an implicit return type. For example, if a function returns a meaningful integer value, declare it int. If it returns no meaningful value, declare it void.
...
Because the compiler assumes that foo() returns a value of type int for this noncompliant code example, UINT_MAX is incorrectly converted to −1.
Compliant Solution (Implicit Return Type)
...
Search for vulnerabilities resulting from the violation of this rule on the CERT website.
Related Guidelines
| CERT C Secure Coding Standard | DCL07-C. Include the appropriate type information in function declarators |
| ISO/IEC TR 24772:2013 | Subprogram Signature Mismatch [OTR] |
| MISRA C:2012 | Rule 8.1 (required) |
...