The analyzer has detected a suspicious type casting. The result of a binary operation is cast to a type with a large range.
Consider the example:
long Multiply(int a, int b)
{
return (long)(a * b);
}
Such conversion is redundant. The 'int' type automatically expands to the 'long' type.
A similar casting pattern can be used to avoid overflow, but the pattern is incorrect. The multiplication of the 'int' type variables still leads to overflow. The meaningless multiplication result is explicitly expanded to the 'long' type.
To protect against overflow correctly, cast one of the arguments to the 'long' type. Here's the fixed code:
long Multiply(int a, int b)
{
return (long)a * b;
}
This diagnostic is classified as: