Rules / cfc-div-zero
Division by zero in CFC: a literal 0 wired into DIV
In a CFC or FBD chart the divisor of a DIV or MOD block is wired to the constant 0. Executing the block raises an exception. It is usually a placeholder left over from debugging.
Severity: Critical
Rule id: cfc-div-zero
CFC: division by a literal zero
What the rule checks
In graphical code (CFC/FBD) the divisor of a DIV/MOD block is wired to a literal constant 0, which is a runtime exception when the block executes. Checked against the connection graph.
What it does to the plant
The task stops on an exception the first time the block executes.
Example
<pou name="FlowCfc" pouType="program"> <interface> <localVars> <variable name="rVolume"><type><REAL/></type></variable> <variable name="rFlow"><type><REAL/></type></variable> </localVars> </interface> <body><addData><data name="cfc" handleUnknown="implementation"><CFC> <inVariable localId="1"><expression>rVolume</expression><connectionPointOut/></inVariable> <inVariable localId="2"><expression>0</expression><connectionPointOut/></inVariable> <block localId="3" typeName="DIV" executionOrderId="0"> <inputVariables> <variable formalParameter="In1"><connectionPointIn><connection refLocalId="1"/></connectionPointIn></variable> <variable formalParameter="In2"><connectionPointIn><connection refLocalId="2"/></connectionPointIn></variable> </inputVariables> <outputVariables><variable formalParameter="Out1"><connectionPointOut/></variable></outputVariables> </block> <outVariable localId="4"><expression>rFlow</expression><connectionPointIn><connection refLocalId="3"/></connectionPointIn></outVariable> </CFC></data></addData></body></pou>
<pou name="FlowCfc" pouType="program"> <interface> <localVars> <variable name="rVolume"><type><REAL/></type></variable> <variable name="rFlow"><type><REAL/></type></variable> </localVars> </interface> <body><addData><data name="cfc" handleUnknown="implementation"><CFC> <inVariable localId="1"><expression>rVolume</expression><connectionPointOut/></inVariable> <inVariable localId="2"><expression>3600.0</expression><connectionPointOut/></inVariable> <block localId="3" typeName="DIV" executionOrderId="0"> <inputVariables> <variable formalParameter="In1"><connectionPointIn><connection refLocalId="1"/></connectionPointIn></variable> <variable formalParameter="In2"><connectionPointIn><connection refLocalId="2"/></connectionPointIn></variable> </inputVariables> <outputVariables><variable formalParameter="Out1"><connectionPointOut/></variable></outputVariables> </block> <outVariable localId="4"><expression>rFlow</expression><connectionPointIn><connection refLocalId="3"/></connectionPointIn></outVariable> </CFC></data></addData></body></pou>
Both listings are run through the linter by an automated test: the rule fires on the first and stays silent on the second.
How to fix
- Wire a variable/setpoint into the divisor input instead of the literal 0; it is usually a debug stub left behind.
- If the divisor can go to zero at runtime, pick a safe value before DIV/MOD (a SEL on a compare-with-0).
Upload a PLCopen XML or CODESYS .export file: the report is free and the code is not stored.
The same linter without uploading a file: command line and GitHub Action.
Related rules
In-depth article
2026-11-26