PLC-lang/rusty

Validate array access in for-loops

Ouverte

#1 255 ouverte le 3 juil. 2024

 (0 commentaire) (0 réaction) (0 personne assignée)Rust (71 forks)auto 404
good first issuemedium-priorityvalidation

Métriques du dépôt

Stars
 (351 étoiles)
Métriques de merge PR
 (Métriques PR en attente)

Description

Is your feature request related to a problem? Please describe. for-loops where the start- and step-values are constant-evaluable currently have no validation for array out-of-bounds accesses where the counter variable is used. For example

VAR
  arr : ARRAY[1..5] OF DINT;
END_VAR

FOR idx := 1 TO 10 DO
  (* ... *)
  arr[idx] := idx;
  (* ... *)
END_FOR 

Based on the end-value we are able to warn the user about a possible out-of-bounds access on arr. Possible because early returns or conditions making sure no out-of-bounds access happen could be in the for-loop.

Describe the solution you'd like Return a warning (not an error), indicating of possible out-of-bounds accesses.

Additional context Data-Flow (or some other kind) analysis would make this much easier, but for very easy cases it should be possible without it.

Guide contributeur