STRONG.TYPE.ASSIGN.INIT
Assignment of two different strong types in initialization
The STRONG.TYPE family of checkers detects situations in which programmer-enforced strong typing (type-defined abstract types) is broken or ignored, allowing the underlying ANSI type semantics to dominate.
The STRONG.TYPE.ASSIGN.INIT checker finds instances of the assignment of two strong types in initialization.
Vulnerability and risk
A compiler following the ANSI standard won't report a warning for this sort of issue, as it checks only the underlying types, not the surface, or programmer-defined, types. As a result, it's possible that a logic error can occur.
Vulnerable code example
Copy
typedef int Weight;
typedef int Speed;
int main() {
Speed s = 0.1;
Weight w = s;
return 0;
}
Klocwork flags line 6, indicating that strong typing is violated in initialization.