SA0040: Possible division by zero
Function | Determines code positions at which division by zero may occur. |
Reason | Division by 0 is not allowed. A variable that is used as a divisor should always be checked for 0 first. Otherwise, a "Divide by Zero" exception may occur at runtime. |
Importance | High |
Sample:
PROGRAM MAIN
VAR CONSTANT
cSample : INT := 100;
END_VAR
VAR
nQuotient1 : INT;
nDividend1 : INT;
nDivisor1 : INT;
nQuotient2 : INT;
nDividend2 : INT;
nDivisor2 : INT;
END_VARnDivisor1 := cSample;
nQuotient1 := nDividend1/nDivisor1; // no error
nQuotient2 := nDividend2/nDivisor2; // => SA0040