The reason I say this, is that recently. Old library code that has been in our project for many years, has recently began generating range checks. In the past, this code built and ran without issue.
Here's an example scenario that's like one that occurred today.
function DoStringStuff(const S: string): string;
var
i: Integer;
len: Integer;
begin
...
while (Result[i] <> #32)
and (i <= len) do
begin
Result[i] := UpperCase(Result[i])[1];
inc(i);
end;
...
end;
When i
is >len
a range check occurs. I fixed it by moving the length check to the beginning. However, I find it strange that it worked at all given the order that's it's evaluating things, where it will ultimately attempt to evaluate an index beyond the string's range.
Any ideas and or suggestions are welcome.