* 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:
sergei 2010-10-06 17:31:08 +00:00
parent a66876704b
commit 1e11244ddf
2 changed files with 28 additions and 34 deletions

View File

@ -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;

View File

@ -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;