Browse Source

Fixed bug on TBytesBuffer.IncreaseSize

PascalCoin 6 years ago
parent
commit
690f0494ce
2 changed files with 6 additions and 4 deletions
  1. 1 1
      src/core/UBaseTypes.pas
  2. 5 3
      src/core/UPCSafeBoxRootHash.pas

+ 1 - 1
src/core/UBaseTypes.pas

@@ -500,7 +500,7 @@ begin
       auxSize := auxSize + FDefaultIncrement;
     until auxSize >= newSize;
     System.SetLength(FBytes,auxSize);
-    FillByte(FBytes[actSize],auxSize - actSize +1,0);
+    FillByte(FBytes[actSize],auxSize - actSize ,0);
   end;
 end;
 

+ 5 - 3
src/core/UPCSafeBoxRootHash.pas

@@ -450,17 +450,19 @@ begin
 end;
 
 procedure TBytesBuffer32Safebox.RedoNextLevelsForMerkleRootHash;
-var i, j : Integer;
+var i : Integer;
+  LNextDefaultIncrement : Integer;
 begin
   if (Self.Length<64) or ((Self.Length MOD 32)<>0) then begin
     FreeAndNil(FNextLevelBytesBuffer);
     Exit;
   end;
   if Not Assigned(FNextLevelBytesBuffer) then begin
-    FNextLevelBytesBuffer := TBytesBuffer32Safebox.Create(32*1000);
+    if (DefaultIncrement >= 64) then LNextDefaultIncrement := DefaultIncrement DIV 2
+    else LNextDefaultIncrement := 32;
+    FNextLevelBytesBuffer := TBytesBuffer32Safebox.Create(LNextDefaultIncrement);
     FNextLevelBytesBuffer.SafeBoxHashCalcType := Self.SafeBoxHashCalcType;
   end;
-  j := Self.Length DIV 64;
   for i := 0 to (((Self.Length+32) DIV 64)-1) do begin
     NotifyUpdated( (i*64), 32);
   end;