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 ?
The beginning character of a string corresponds to index 0 and the last character corresponds to the index (length of string)-1 . The length of a string is the number of characters it contains, including spaces, punctuation, and control characters.
A zero-based approach seeks to link organizational designs to strategic priorities (for example, areas for investment compared with efficiency optimization) instead of a “one-size-fits-all” solution across the business.
All arrays must be zero-indexed. In Microsoft Visual Basic 6.0, you can define arrays with the lower bounds and upper bounds set to any integer. In Microsoft Visual Basic . NET, the lower bound of every array dimension is zero (0).
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With