Browse Source

* Fix bug #26370: A multi-dimensional variant array is "empty" when any of its dimensions has zero range, range of other dimensions does not matter.

git-svn-id: trunk@29324 -
sergei 10 years ago
parent
commit
ba61a9f95c
3 changed files with 23 additions and 6 deletions
  1. 1 0
      .gitattributes
  2. 3 6
      packages/rtl-objpas/src/inc/variants.pp
  3. 19 0
      tests/test/units/variants/tw26370.pp

+ 1 - 0
.gitattributes

@@ -12596,6 +12596,7 @@ tests/test/units/sysutils/twstrcmp.pp svneol=native#text/plain
 tests/test/units/ucomplex/tcsqr1.pp svneol=native#text/pascal
 tests/test/units/ucomplex/tcsqr1.pp svneol=native#text/pascal
 tests/test/units/variants/tcustomvariant.pp svneol=native#text/plain
 tests/test/units/variants/tcustomvariant.pp svneol=native#text/plain
 tests/test/units/variants/tvararrayofintf.pp svneol=native#text/plain
 tests/test/units/variants/tvararrayofintf.pp svneol=native#text/plain
+tests/test/units/variants/tw26370.pp svneol=native#text/plain
 tests/test/units/variants/tw27044.pp svneol=native#text/plain
 tests/test/units/variants/tw27044.pp svneol=native#text/plain
 tests/test/uobjc24.pp svneol=native#text/plain
 tests/test/uobjc24.pp svneol=native#text/plain
 tests/test/uobjc26.pp svneol=native#text/plain
 tests/test/uobjc26.pp svneol=native#text/plain

+ 3 - 6
packages/rtl-objpas/src/inc/variants.pp

@@ -483,13 +483,10 @@ function TVariantArrayIterator.AtEnd: Boolean;
 var
 var
   i : sizeint;
   i : sizeint;
 begin
 begin
-  result:=true;
+  result:=false;
   for i:=0 to Pred(Dims) do
   for i:=0 to Pred(Dims) do
-    if Coords^[i] < Bounds^[i].LowBound + Bounds^[i].ElementCount then
-      begin
-        result:=false;
-        exit;
-      end;
+    if Coords^[i] >= Bounds^[i].LowBound + Bounds^[i].ElementCount then
+        result:=true;
 end;
 end;
 
 
 {$pop}// {$r-} for TVariantArrayIterator
 {$pop}// {$r-} for TVariantArrayIterator

+ 19 - 0
tests/test/units/variants/tw26370.pp

@@ -0,0 +1,19 @@
+{$mode objfpc}
+uses Variants;
+
+procedure test;
+var
+  Bounds: Array [0..1] of TVarArrayBound;
+  V1, V2: Variant;
+begin
+  Bounds[0].lowbound := 0;
+  Bounds[0].elementcount := 1;
+  Bounds[1].lowbound := 0;
+  Bounds[1].elementcount := 0;
+  V1 := VarArrayCreate(@Bounds, 2, varVariant);
+  V2 := V1; // <- Exception EVariantBadIndexError!!!!!
+end;
+ 
+begin
+  test;
+end.