mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-12 07:46:00 +02:00
* Fix overflow in Delete procedure for Wide- and UnicodeStrings when its Size argument is MaxInt. Now using the same code as in AnsiString version. Mantis #17514.
git-svn-id: trunk@16092 -
This commit is contained in:
parent
a66876704b
commit
1e11244ddf
@ -1587,23 +1587,20 @@ Procedure Delete (Var S : UnicodeString; Index,Size: SizeInt);
|
|||||||
Var
|
Var
|
||||||
LS : SizeInt;
|
LS : SizeInt;
|
||||||
begin
|
begin
|
||||||
If Length(S)=0 then
|
LS:=Length(S);
|
||||||
|
if (Index>LS) or (Index<=0) or (Size<=0) then
|
||||||
exit;
|
exit;
|
||||||
if index<=0 then
|
|
||||||
exit;
|
|
||||||
LS:=PUnicodeRec(Pointer(S)-UnicodeFirstOff)^.Len div sizeof(UnicodeChar);
|
|
||||||
if (Index<=LS) and (Size>0) then
|
|
||||||
begin
|
|
||||||
UniqueString (S);
|
UniqueString (S);
|
||||||
if Size+Index>LS then
|
{ (Size+Index) will overflow if Size=MaxInt. }
|
||||||
|
if Size>LS-Index then
|
||||||
Size:=LS-Index+1;
|
Size:=LS-Index+1;
|
||||||
if Index+Size<=LS then
|
if Size<=LS-Index then
|
||||||
begin
|
begin
|
||||||
Dec(Index);
|
Dec(Index);
|
||||||
Move(PUnicodeChar(S)[Index+Size],PUnicodeChar(S)[Index],(LS-Index-Size+1)*sizeof(UnicodeChar));
|
Move(PUnicodeChar(S)[Index+Size],PUnicodeChar(S)[Index],(LS-Index-Size+1)*sizeof(UnicodeChar));
|
||||||
end;
|
end;
|
||||||
Setlength(s,LS-Size);
|
Setlength(s,LS-Size);
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
@ -945,23 +945,20 @@ Procedure Delete (Var S : WideString; Index,Size: SizeInt);
|
|||||||
Var
|
Var
|
||||||
LS : SizeInt;
|
LS : SizeInt;
|
||||||
begin
|
begin
|
||||||
If Length(S)=0 then
|
LS:=Length(S);
|
||||||
|
if (Index>LS) or (Index<=0) or (Size<=0) then
|
||||||
exit;
|
exit;
|
||||||
if index<=0 then
|
|
||||||
exit;
|
|
||||||
LS:=PWideRec(Pointer(S)-WideFirstOff)^.Len div sizeof(WideChar);
|
|
||||||
if (Index<=LS) and (Size>0) then
|
|
||||||
begin
|
|
||||||
UniqueString (S);
|
UniqueString (S);
|
||||||
if Size+Index>LS then
|
{ (Size+Index) will overflow if Size=MaxInt. }
|
||||||
|
if Size>LS-Index then
|
||||||
Size:=LS-Index+1;
|
Size:=LS-Index+1;
|
||||||
if Index+Size<=LS then
|
if Size<=LS-Index then
|
||||||
begin
|
begin
|
||||||
Dec(Index);
|
Dec(Index);
|
||||||
Move(PWideChar(S)[Index+Size],PWideChar(S)[Index],(LS-Index-Size+1)*sizeof(WideChar));
|
Move(PWideChar(S)[Index+Size],PWideChar(S)[Index],(LS-Index-Size+1)*sizeof(WideChar));
|
||||||
end;
|
end;
|
||||||
Setlength(s,LS-Size);
|
Setlength(s,LS-Size);
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user