Code inspection: Division by zero in at least one execution path
This inspection reports integer division where the divisor can be 0 on at least one execution path.
Example
int Divide(int value, bool useZero)
{
var divisor = useZero ? 0 : 2;
return value / divisor;
}
int Divide(int value, bool useZero)
{
var divisor = useZero ? 0 : 2;
if (divisor == 0)
return 0;
return value / divisor;
}
Quick-fix
There is no dedicated quick-fix for this inspection. A typical correction is to ensure the divisor cannot be zero before the division happens.
01 April 2026