mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-22 00:29:33 +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
|
||||
LS : SizeInt;
|
||||
begin
|
||||
If Length(S)=0 then
|
||||
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);
|
||||
if Size+Index>LS then
|
||||
Size:=LS-Index+1;
|
||||
if Index+Size<=LS then
|
||||
begin
|
||||
Dec(Index);
|
||||
Move(PUnicodeChar(S)[Index+Size],PUnicodeChar(S)[Index],(LS-Index-Size+1)*sizeof(UnicodeChar));
|
||||
end;
|
||||
Setlength(s,LS-Size);
|
||||
end;
|
||||
LS:=Length(S);
|
||||
if (Index>LS) or (Index<=0) or (Size<=0) then
|
||||
exit;
|
||||
|
||||
UniqueString (S);
|
||||
{ (Size+Index) will overflow if Size=MaxInt. }
|
||||
if Size>LS-Index then
|
||||
Size:=LS-Index+1;
|
||||
if Size<=LS-Index then
|
||||
begin
|
||||
Dec(Index);
|
||||
Move(PUnicodeChar(S)[Index+Size],PUnicodeChar(S)[Index],(LS-Index-Size+1)*sizeof(UnicodeChar));
|
||||
end;
|
||||
Setlength(s,LS-Size);
|
||||
end;
|
||||
|
||||
|
||||
|
@ -945,23 +945,20 @@ Procedure Delete (Var S : WideString; Index,Size: SizeInt);
|
||||
Var
|
||||
LS : SizeInt;
|
||||
begin
|
||||
If Length(S)=0 then
|
||||
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);
|
||||
if Size+Index>LS then
|
||||
Size:=LS-Index+1;
|
||||
if Index+Size<=LS then
|
||||
begin
|
||||
Dec(Index);
|
||||
Move(PWideChar(S)[Index+Size],PWideChar(S)[Index],(LS-Index-Size+1)*sizeof(WideChar));
|
||||
end;
|
||||
Setlength(s,LS-Size);
|
||||
end;
|
||||
LS:=Length(S);
|
||||
if (Index>LS) or (Index<=0) or (Size<=0) then
|
||||
exit;
|
||||
|
||||
UniqueString (S);
|
||||
{ (Size+Index) will overflow if Size=MaxInt. }
|
||||
if Size>LS-Index then
|
||||
Size:=LS-Index+1;
|
||||
if Size<=LS-Index then
|
||||
begin
|
||||
Dec(Index);
|
||||
Move(PWideChar(S)[Index+Size],PWideChar(S)[Index],(LS-Index-Size+1)*sizeof(WideChar));
|
||||
end;
|
||||
Setlength(s,LS-Size);
|
||||
end;
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user