Reputation: 13357
in system.sysutils.pas
, in Rio they add this instruction:
var intPart: String;
... IntPart.Chars[length(IntPart)] in ['1','3','5','7','9'] ...
But as far as i know, s.Chars[xx] will be always zero-based string so doing IntPart.Chars[length(IntPart)] in ['1','3','5','7','9']
will always go out of the boundary ?
it's must not be written instead
... IntPart.Chars[length(IntPart)-1] in ['1','3','5','7','9'] ...
Or I miss something ?
Upvotes: 8
Views: 754
Reputation: 34899
But as far as i know, s.Chars[xx] will be always zero-based string
Yes, the TStringHelper
routines are written to operate on strings as zero based, regardless of the compiler settings ({$ZEROBASEDSTRINGS ON/OFF}). See SysUtils.TStringHelper.Chars.
so doing IntPart.Chars[length(IntPart)] in ['1','3','5','7','9'] will always go out of the boundary ?
That is correct. It should have been Length(IntPart)-1
.
Reported as: SysUtils.InternalTextToCurrency accesses a string out of bounds
Update: Fixed in Delphi 10.3.3 Rio.
Furthermore, when range check is on, IntPart.Chars[length(IntPart)]
should have raised an exception. This is also bug (in TStringHelpers.Chars
).
Reported as: TStringHelper.Chars does not issue a range error when index is out of bounds
Upvotes: 10