free quality report for PLCopenXML exports

Rules / array-bounds

Array index out of bounds in Structured Text: CODESYS does not always catch it

A constant index outside the declared ARRAY[lo..hi] reads or writes foreign memory every time the line runs. Without an active CheckBounds function the runtime will not intercept it.

Severity: Critical Rule id: array-bounds Array index out of bounds

What the rule checks

A constant index falls outside the declared ARRAY[lo..hi] bounds, so reaching this line reads or writes memory that isn't yours. Without active implicit checks the runtime won't intercept it. Checked for one-dimensional arrays with numeric bounds and a literal index.

What it does to the plant

Neighbouring variables get corrupted: random setpoints, commands that seem to come from nowhere, faults that never reproduce on the bench.

Example

Bad: the rule fires
PROGRAM ZonesVAR    aTemp : ARRAY[1..4] OF REAL;END_VARaTemp[5] := 0.0;
Fixed: the rule is silent
PROGRAM ZonesVAR    aTemp : ARRAY[1..4] OF REAL;END_VARaTemp[4] := 0.0;

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

  1. Bring the index into the declared range or widen the array bounds.
  2. Check before access: IF idx >= LO AND idx <= HI THEN arr[idx] … END_IF
Check your project

Upload a PLCopen XML or CODESYS .export file: the report is free and the code is not stored.

Local version on GitHub →

The same linter without uploading a file: command line and GitHub Action.

Related rules

2026-11-26

Processing happens in memory, and the uploaded code is not stored. The tool advises; code changes are up to the engineer (see what the linter can't see). What happens to your code → · Rule reference · Your code & privacy · Industry benchmark · Feedback · GitHub