浏览代码

* rtl: fix TFPGList Add/Insert hang/crash (issue #15500)

git-svn-id: trunk@14718 -
micha 15 年之前
父节点
当前提交
215823c88f
共有 1 个文件被更改,包括 9 次插入5 次删除
  1. 9 5
      rtl/objpas/fgl.pp

+ 9 - 5
rtl/objpas/fgl.pp

@@ -490,9 +490,13 @@ begin
   if (Index < 0) or (Index > FCount) then
     Error(SListIndexError, Index);
   if FCount = FCapacity then Self.Expand;
-  if Index<FCount then
-    System.Move(InternalItems[Index]^, InternalItems[Index+1]^, (FCount - Index) * FItemSize);
   Result := InternalItems[Index];
+  if Index<FCount then
+  begin
+    System.Move(Result^, (Result+FItemSize)^, (FCount - Index) * FItemSize);
+    { clear for compiler assisted types }
+    System.FillByte(Result^, FItemSize, 0);
+  end;
   Inc(FCount);
 end;
 
@@ -695,7 +699,7 @@ begin
   if ResPtr <> nil then
     Result := T(ResPtr^)
   else
-    FillByte(Result, 0, sizeof(T));
+    FillByte(Result, sizeof(T), 0);
 end;
 
 function TFPGList.First: T;
@@ -801,7 +805,7 @@ begin
   if ResPtr <> nil then
     Result := T(ResPtr^)
   else
-    FillByte(Result, 0, sizeof(T));
+    FillByte(Result, sizeof(T), 0);
 end;
 
 function TFPGObjectList.First: T;
@@ -898,7 +902,7 @@ begin
   if ResPtr <> nil then
     Result := T(ResPtr^)
   else
-    FillByte(Result, 0, sizeof(T));
+    FillByte(Result, sizeof(T), 0);
 end;
 
 function TFPGInterfacedObjectList.First: T;