From ba61a9f95c2bf063cfe4af54c286710c4dcab5f7 Mon Sep 17 00:00:00 2001 From: sergei Date: Thu, 25 Dec 2014 16:59:52 +0000 Subject: [PATCH] * 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 - --- .gitattributes | 1 + packages/rtl-objpas/src/inc/variants.pp | 9 +++------ tests/test/units/variants/tw26370.pp | 19 +++++++++++++++++++ 3 files changed, 23 insertions(+), 6 deletions(-) create mode 100644 tests/test/units/variants/tw26370.pp diff --git a/.gitattributes b/.gitattributes index f76a9a7eac..ea7641c39d 100644 --- a/.gitattributes +++ b/.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/variants/tcustomvariant.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/uobjc24.pp svneol=native#text/plain tests/test/uobjc26.pp svneol=native#text/plain diff --git a/packages/rtl-objpas/src/inc/variants.pp b/packages/rtl-objpas/src/inc/variants.pp index d2f2b0207d..f12c55f539 100644 --- a/packages/rtl-objpas/src/inc/variants.pp +++ b/packages/rtl-objpas/src/inc/variants.pp @@ -483,13 +483,10 @@ function TVariantArrayIterator.AtEnd: Boolean; var i : sizeint; begin - result:=true; + result:=false; 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; {$pop}// {$r-} for TVariantArrayIterator diff --git a/tests/test/units/variants/tw26370.pp b/tests/test/units/variants/tw26370.pp new file mode 100644 index 0000000000..ae816390a4 --- /dev/null +++ b/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. \ No newline at end of file