pa[index] wrong if item is array
Original Reporter info from Mantis: nanobit @nanobit
-
Reporter name:
Original Reporter info from Mantis: nanobit @nanobit
- Reporter name:
Description:
ArrayPointer (pa) to array of items fails for indexed access,
if the arrayPointer is a typed itemPointer (^Titem with {$PointerMath on}),
and Titem is arrayType (subarray).
(pa + index) works, pa[index] fails, but they should access the same item.
Steps to reproduce:
procedure test;
type Tatom = single;
type Titem = packed array[0..7] of Tatom; // buggy (if Titem is array)
//type Titem = record d1, d2: Tatom; end; // ok (if Titem is record)
type PItem = ^Titem;
{$PointerMath on}
type PItemArray = ^Titem;
{$PointerMath off}
var
memoryItems: array of Titem;
pa: PItemArray;
pItemOk, pItemWrong: PItem;
stride: integer;
begin
setLength( memoryItems, 100);
pa := @memoryItems[0];
pItemOk := pa + 1;
pItemWrong := @pa[1];
stride := PtrUInt(pItemOk) - PtrUInt(pa);
assert( stride = sizeOf( Titem)); // correct
stride := PtrUInt(pItemWrong) - PtrUInt(pa);
// assert( stride = sizeOf( Titem)); // true would be correct
assert( stride = sizeOf( Tatom)); // true means bug:
// pa[0], pa[1], ... are atoms, but should be items (according to PItemArray = ^Titem)
end;
Mantis conversion info:
- Mantis ID: 35745
- OS: Windows
- OS Build: 10
- Platform: win32
- Version: 3.2.0