Oberon.Call Can Leave 'res' Undefined

Report any suspected bugs that you find
Post Reply
gray
Posts: 71
Joined: Tue Feb 12, 2019 2:59 am
Location: Mauritius

Oberon.Call Can Leave 'res' Undefined

Post by gray » Wed Jun 02, 2021 4:39 am

This applies to Embedded Oberon.

Oberon.Call:

Code: Select all

PROCEDURE Call* (name: ARRAY OF CHAR; VAR res: INTEGER);
  (* .. *)
BEGIN i := 0; ch := name[0];
  WHILE (ch # ".") & (ch # 0X) DO Mname[i] := ch; INC(i); ch := name[i] END ;
  IF ch = "." THEN
    (* .. *)
  END
END Call;
Oberon.Call has a code path that leaves 'res' in an undefined state, namely if no dot "." is found in the command string, which can result in erroneous error reporting due to the way it is called from Oberon.Loop:

Code: Select all

  (* .. *)
  GetCommand(ch);
  IF Par.text.string[0] # 0X THEN
    Call(Par.text.string, res);
    IF res # 0 THEN
      WriteError(res, Par.text.string)
    END
  END
  (* .. *)
Project Oberon sets 'res := 5' in this case, "Unknown command" in EO, which seems appropriate and useful:

Code: Select all

PROCEDURE Call* (name: ARRAY OF CHAR; VAR res: INTEGER);
  (* .. *)
BEGIN i := 0; ch := name[0];
  (* .. *)
  IF ch = "." THEN
    (* .. * )
  ELSE res := 5
  END
END Call;

Post Reply