mirror of
https://github.com/vishapoberon/compiler.git
synced 2026-04-05 23:22:25 +00:00
fix in ooc Strings modules to prevent index out of range error.
This commit is contained in:
parent
bc8adf76c1
commit
32ec67552f
2 changed files with 11 additions and 2 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue