* fixed missing range checks in r33056

* fixed pos(unicodestring) with a non-zero offset added in r33056 (fixes
    tests/test/units/system/tstring.pp)

git-svn-id: trunk@33120 -
This commit is contained in:
Jonas Maebe 2016-02-25 19:56:49 +00:00
parent 03d4ada29e
commit 0deacf9fba

View File

@ -1166,7 +1166,7 @@ var
pc : punicodechar; pc : punicodechar;
begin begin
Pos:=0; Pos:=0;
if Length(SubStr)>0 then if (Length(SubStr)>0) and (Offset>0) and (Offset<=Length(Source)) then
begin begin
MaxLen:=Length(source)-Length(SubStr)-(OffSet-1); MaxLen:=Length(source)-Length(SubStr)-(OffSet-1);
i:=0; i:=0;
@ -1177,7 +1177,7 @@ begin
if (SubStr[1]=pc^) and if (SubStr[1]=pc^) and
(CompareWord(Substr[1],pc^,Length(SubStr))=0) then (CompareWord(Substr[1],pc^,Length(SubStr))=0) then
begin begin
Pos:=i; Pos:=Offset+i-1;
exit; exit;
end; end;
inc(pc); inc(pc);
@ -1195,15 +1195,18 @@ var
i: SizeInt; i: SizeInt;
pc : punicodechar; pc : punicodechar;
begin begin
pc:=@s[OffSet]; if (Offset>0) and (Offset<=length(s)) then
for i:=OffSet to length(s) do
begin begin
if pc^=c then pc:=@s[OffSet];
begin for i:=OffSet to length(s) do
pos:=i; begin
exit; if pc^=c then
end; begin
inc(pc); pos:=i;
exit;
end;
inc(pc);
end;
end; end;
pos:=0; pos:=0;
end; end;
@ -1241,17 +1244,20 @@ var
wc : unicodechar; wc : unicodechar;
pc : punicodechar; pc : punicodechar;
begin begin
wc:=c; if (Offset>0) and (Offset<=Length(S)) then
pc:=@s[OffSet]; begin
for i:=OffSet to length(s) do wc:=c;
begin pc:=@s[OffSet];
if pc^=wc then for i:=OffSet to length(s) do
begin begin
pos:=i; if pc^=wc then
exit; begin
end; pos:=i;
inc(pc); exit;
end; end;
inc(pc);
end;
end;
pos:=0; pos:=0;
end; end;
{$endif FPC_HAS_POS_CHAR_UNICODESTR} {$endif FPC_HAS_POS_CHAR_UNICODESTR}