pchar(pointer(string)) broken with inlined range checking
Original Reporter info from Mantis: BeniBela @benibela
-
Reporter name: Benito van der Zander
Original Reporter info from Mantis: BeniBela @benibela
- Reporter name: Benito van der Zander
Description:
With the newest fpc
program xx;
uses sysutils; {$mode objfpc}{$H+}
function strlsIndexOf(str, searched: pansichar; l1, l2: longint): longint;
begin
result:=-1; //function removed for minimal example
end;
function strindexof(const str, searched: string): longint; inline;
begin
if str = '' then begin result := 0; exit; end;
result := strlsIndexOf(pchar(pointer(str)) , pchar(searched), length(str) , length(searched));
if result < 0 then begin result := 0; exit; end;
inc(result);
end;
function strBefore(const s, sep: string): string;
var
i: Integer;
begin
i := strIndexOf(s, sep); // line 26
if i = 0 then result := ''
else result := copy(s, 1, i-1);
end;
begin
strBefore('hallo', 'a');
end.
throws
EAccessViolation: Access violation
$000000000040031E STRBEFORE, line 26 of xx.lpr
There is no exception when compiled without -Cr, below -O2, without inline, or with a normal pchar(str) cast
Mantis conversion info:
- Mantis ID: 32576
- Build: r37480
- Version: 3.1.1
- Fixed in version: 3.1.1
- Fixed in revision: 38069 (#10ea6524)