CERT.EXPR.PASS_NON_STD_LAYOUT
Do not pass a nonstandard-layout type object across execution boundaries.
Vulnerability and risk
Standard-layout types can be used to communicate with code written in other programming languages, as the layout of the type is strictly specified.
Non-standard-layout types should not be used because different languages and different compiler versions may align member data differently.
This checker looks for function calls where the called function is declared "extern" with a linkage specifier that is not "C++". If a nonstandard-layout object is passed then a violation is reported.
Mitigation and prevention
Don't pass nonstandard-layout objects to functions defined in other languages.
Example
Copy
struct B {
int i, j;
};
struct D : B {
float f;
};
extern "C" void func(void *);
void foo(D *d) {
func(d);
}
A vilolation will be reported on line 12.