Hi,
it seems that GPC ignores the upper bounds of $SUBJ when they are automatically converted to CString:
[pas]% cat slice.pas program Foo (Input, Output);
procedure Bar (S: CString); begin {$local X+} WriteLn (S) {$endlocal} end;
var S: String (20);
begin S := 'failedOKfailed'; Bar (S[7 .. 8]) end. [pas]% gpc slice.pas [pas]% ./a.out OKfailed
Emil Jerabek
Emil Jerabek wrote:
it seems that GPC ignores the upper bounds of $SUBJ when they are automatically converted to CString:
[pas]% cat slice.pas program Foo (Input, Output);
procedure Bar (S: CString); begin {$local X+} WriteLn (S) {$endlocal} end;
var S: String (20);
begin S := 'failedOKfailed'; Bar (S[7 .. 8]) end.
Thanks for the report. The problem was actually larger: Any assignment/parameter passing of a fixed string (i.e., `array ... of Char') to a CString did not get the #0 appended (so the CString just extended until the next 0 in memory, which here happened to be after the end of S). I've fixed this now (this means, the slice is now copied to a temporary variable where the #0 can be appended). (emil17.pas, fjf390[a-d].pas)
Frank