Skip to content

Commit 13f2391

Browse files
committed
Fix some out of bounds errors caught by the debug build
1 parent 597754b commit 13f2391

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

M2/Macaulay2/d/ctype.d

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,12 @@ ismathoperator(c1:char, c2:char):bool := (
6767
ismathoperator((int(uchar(c1)) << 8) | int(uchar(c2))));
6868

6969
export isvalidsymbol(s:string):bool := (
70-
if !isalpha(s.0) then return false;
71-
if ismathoperator(s.0, s.1) && length(s) == utf8charlength(s.0)
70+
n := length(s);
71+
if n > 0 && !isalpha(s.0) then return false;
72+
if n > 1 && ismathoperator(s.0, s.1) && n == utf8charlength(s.0)
7273
then return true;
73-
for i from 0 to length(s) - 1 do (
74-
if !isalnum(s.i) || ismathoperator(s.i, s.(i + 1))
74+
for i from 0 to n - 1 do (
75+
if !isalnum(s.i) || (n > i + 1 && ismathoperator(s.i, s.(i + 1)))
7576
then return false);
7677
true);
7778

0 commit comments

Comments
 (0)