Răsfoiți Sursa

Merged revisions 169-170 via svnmerge from
/trunk

git-svn-id: branches/fixes_2_0@171 -

fpc 20 ani în urmă
părinte
comite
f9e829c4ed
4 a modificat fișierele cu 23 adăugiri și 6 ștergeri
  1. 1 0
      .gitattributes
  2. 6 4
      rtl/inc/varianth.inc
  3. 6 2
      rtl/objpas/varutils.inc
  4. 10 0
      tests/tbs/tb0492.pp

+ 1 - 0
.gitattributes

@@ -4982,6 +4982,7 @@ tests/tbs/tb0486.pp svneol=native#text/plain
 tests/tbs/tb0487.pp svneol=native#text/plain
 tests/tbs/tb0488.pp svneol=native#text/plain
 tests/tbs/tb0489.pp svneol=native#text/plain
+tests/tbs/tb0492.pp svneol=native#text/plain
 tests/tbs/ub0060.pp svneol=native#text/plain
 tests/tbs/ub0069.pp svneol=native#text/plain
 tests/tbs/ub0119.pp svneol=native#text/plain

+ 6 - 4
rtl/inc/varianth.inc

@@ -57,15 +57,17 @@ type
      elementcount,lowbound  : SizeInt;
    end;
 
+   tvararrayboundarray = array[0..0] of tvararraybound;
+   tvararraycoorarray = array[0..0] of SizeInt;
+
    tvararray = packed record
       dimcount,flags : word;
-      elementsize,lockcount : longint;
+      elementsize : ptrint;
+      lockcount : longint;
       data : pointer;
-      bounds : array[0..255] of tvararraybound;
+      bounds : tvararrayboundarray;
    end;
 
-   tvararrayboundarray = array[0..0] of tvararraybound;
-   tvararraycoorarray = array[0..0] of SizeInt;
 
    tvarop = (opadd,opsubtract,opmultiply,opdivide,opintdivide,opmodulus,
              opshiftleft,opshiftright,opand,opor,opxor,opcompare,opnegate,

+ 6 - 2
rtl/objpas/varutils.inc

@@ -379,7 +379,8 @@ Function SafeArrayCreate(VarType, Dim: SizeInt; const Bounds: TVarArrayBoundArra
 Function SafeArrayAllocDescriptor(DimCount: SizeInt; var psa: PVarArray): HRESULT;stdcall;
 begin
   try
-    psa:=GetMem(SizeOf(TVarArray) + SizeOf(TVarArrayBound) * (DimCount - 1));
+    { one bound item is included in TVarArray }
+    psa:=GetMem(SizeOf(TVarArray) + SizeOf(TVarArrayBound)*(DimCount-1));
     Result:=VAR_OK;
   except
     On E : Exception do
@@ -391,7 +392,10 @@ Function SafeArrayAllocData(psa: PVarArray): HRESULT;stdcall;
 begin
   try
     With psa^ do
-      Data:=GetMem(SafeArrayElementTotal(psa)*ElementSize);
+      begin 
+        Data:=GetMem(SafeArrayElementTotal(psa)*ElementSize);
+        fillchar(Data^,SafeArrayElementTotal(psa)*ElementSize,0);
+      end;
     Result:=VAR_OK;
   except
     On E : Exception do

+ 10 - 0
tests/tbs/tb0492.pp

@@ -0,0 +1,10 @@
+program pokus;
+
+uses
+  Variants;
+
+var
+  v: Variant;
+begin
+  v := VarArrayCreate([0, 1], varVariant);
+end.