fix in ooc Strings modules to prevent index out of range error.

This commit is contained in:
Norayr Chilingarian 2022-03-15 17:20:41 +04:00
parent bc8adf76c1
commit 32ec67552f
2 changed files with 11 additions and 2 deletions

View file

@ -63,7 +63,11 @@ PROCEDURE Length* (stringVal: ARRAY OF CHAR): INTEGER;
i: INTEGER;
BEGIN
i := 0;
WHILE (stringVal[i] # 0X) DO
(* note from noch:
original ooc code below, commented out, leads to
index out of range runtime error
WHILE (stringVal[i] # 0X) DO *)
WHILE ((i < LEN(stringVal)) & (stringVal[i] # 0X)) DO
INC (i)
END;
RETURN i

View file

@ -59,7 +59,12 @@ PROCEDURE Length* (stringVal: ARRAY OF CHAR): INTEGER;
i: INTEGER;
BEGIN
i := 0;
WHILE (stringVal[i] # 0X) DO
(* note from noch:
this original ooc code crashes with index out of range
because it doesn't expect a string which has no 0X character
so i had to change it
WHILE (stringVal[i] # 0X) DO *)
WHILE ((i < LEN(stringVal)) & (stringVal[i] # 0X)) DO
INC (i)
END;
RETURN i