PLC-lang/rusty

Validate array access in for-loops

开放

#1,255 创建于 2024年7月3日

 (0 条评论) (0 个反应) (0 位负责人)Rust (71 个派生)auto 404
good first issuemedium-priorityvalidation

仓库指标

星标
 (351 个星标)
PR 合并指标
 (PR 指标待抓取)

描述

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.

贡献者指南