STRONG.TYPE.ASSIGN.RETURN
Assignment strong type with inexplicit return
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.RETURN checker finds function return statements in which a strong type is expected, but not present.
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 float Speed;
Speed getTurtleSpeed()
{
return 1.0;
}
Klocwork flags line 5, indicating that the returned value is not of the expected strong type Speed.
Fixed code example
Copy
typedef float Speed;
Speed getTurtleSpeed()
{
return (Speed)1.0;
}
When the returned value is explicitly cast to the strong type Speed, no report is produced.