PLC-lang/rusty

Validate array access in for-loops

オープン

#1,255 opened on 2024/07/03

 (0 件のコメント) (0 件のリアクション) (0 人の担当者)Rust (71 件のフォーク)auto 404
good first issuemedium-priorityvalidation

Repository metrics

Stars
 (351 個のスター)
PR merge metrics
 (PR metrics pending)

説明

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.

コントリビューターガイド