DEVELOPMENT EDITION · 769442725406
Diagnostics Reference
On this page

B4104: division by zero check might fail

Catalog status: active. Default severity: error. Stable name: division-check. Family: Executable checks.

The divisor of /, rem or mod might be zero, which raises Constraint_Error at run time.

Example (Vada)

   function Share (Total : Natural; People : Natural) return Natural is (Total / People);

Example (Varc)

    pub fn share(total: Natural, people: Natural) -> Natural = total / people;

What to do (Vada)

Use a subtype that excludes zero for the divisor (People : Positive), add a precondition (with Pre => People /= 0), or test it before dividing.

What to do (Varc)

Use a subtype that excludes zero for the divisor (people: Positive), add a precondition (requires people != 0), or test it before dividing.

Regression source and further reading

Complete regression example: source, command arguments and expected results. The fixture deliberately reproduces this diagnostic.

See executable checks, the code index, and diagnostic interpretation for modes, replay, fix-its and JSON.