...
The C Standard identifies four situations in which undefined behavior (UB) may arise as a result of incompatible declarations of the same function or object:
UB | Description | Code |
|---|---|---|
Two declarations of the same object or function specify types that are not compatible (6.2.7). | All noncompliant code in this guideline | |
| 31 | Two identifiers differ only in nonsignificant characters (6.4.2.1). | Excessively Long Identifiers |
An object has its stored value accessed other than by an lvalue of an allowable type (6.5). | Incompatible Object Declarations | |
| A function is defined with a type that is not compatible with the type (of the expression) pointed to by the expression that denotes the called function (6.5.2.2). | Incompatible Function Declarations |
Although the effect of two incompatible declarations simply appearing in the same program may be benign on most implementations, the effects of invoking a function through an expression whose type is incompatible with the function definition are typically catastrophic. Similarly, the effects of accessing an object using an lvalue of a type that is incompatible with the object definition may range from unintended information exposure to memory overwrite to a hardware trap.
...
| Code Block | ||||
|---|---|---|---|---|
| ||||
/* In bashline.h */
extern char * bash_groupname_completion(const char *, int);
/* In a.c */
#include "bashline.h"
void f(const char *s, int i) {
bash_groupname_completion(s, i);
}
/* In b.c */
int bash_groupname_completion_funct; |
Risk Assessment
Rule | Severity | Likelihood | Remediation Cost | Priority | Level |
|---|---|---|---|---|---|
DCL40-C | Low | Unlikely | Medium | P2 | L3 |
Automated Detection
Tool | Version | Checker | Description | ||||||
|---|---|---|---|---|---|---|---|---|---|
| Astrée |
| type-compatibility | Partially checked | ||||||
| CodeSonar |
| LANG.STRUCT.DECL.IF LANG.STRUCT.DECL.IO | Inconsistent function declarations Inconsistent object declarations | ||||||
| Coverity |
| MISRA C 2012 Rule 8.4 | Implemented | ||||||
| LDRA tool suite | 8.5.4 | 1 X, 17 D | Partially implemented | ||||||
| Parasoft C/C++test |
| CODSTA-118, MISRA2004-8_4 | Implemented | ||||||
| Parasoft Insure++ |
| runtime | ||||||||
| Polyspace Bug Finder | R2016a | Declaration mismatch | Mismatch between function or variable declarations | ||||||
| PRQA QA-C |
| 1510,776,778,779,789 | Fully implemented | ||||||
| PRQA QA-C++ |
| 1510 |
| RuleChecker |
| type-compatibility | Partially checked |
Related Guidelines
Key here (explains table format and definitions)
Taxonomy | Taxonomy item | Relationship |
|---|---|---|
| ISO/IEC TS 17961 | Declaring the same function or object in incompatible ways [funcdecl] | Prior to 2018-01-12: CERT: Unspecified Relationship |
| MISRA C:2012 | Rule 8.4 (required) | Prior to 2018-01-12: CERT: Unspecified Relationship |
Bibliography
| [Hatton 1995] | Section 2.8.3 |
| [ISO/IEC 9899:2011] | 6.7.6.3, "Function Declarators (including Prototypes)" J.2, "Undefined Behavior" |
...
...