Browse Source

* Attempt to avoid overflow when reallocating stream

git-svn-id: trunk@34518 -
michael 9 years ago
parent
commit
bc6819aa91
1 changed files with 6 additions and 2 deletions
  1. 6 2
      rtl/objpas/classes/streams.inc

+ 6 - 2
rtl/objpas/classes/streams.inc

@@ -667,14 +667,18 @@ end;
 
 
 function TMemoryStream.Realloc(var NewCapacity: PtrInt): Pointer;
 function TMemoryStream.Realloc(var NewCapacity: PtrInt): Pointer;
 
 
+Var
+  GC : PtrInt;
+
 begin
 begin
   If NewCapacity<0 Then
   If NewCapacity<0 Then
     NewCapacity:=0
     NewCapacity:=0
   else
   else
     begin
     begin
+      GC:=FCapacity + (FCapacity div 4);
       // if growing, grow at least a quarter
       // if growing, grow at least a quarter
-      if (NewCapacity>FCapacity) and (NewCapacity < (5*FCapacity) div 4) then
-        NewCapacity := (5*FCapacity) div 4;
+      if (NewCapacity>FCapacity) and (NewCapacity < GC) then
+        NewCapacity := GC;
       // round off to block size.
       // round off to block size.
       NewCapacity := (NewCapacity + (TMSGrow-1)) and not (TMSGROW-1);
       NewCapacity := (NewCapacity + (TMSGrow-1)) and not (TMSGROW-1);
     end;
     end;