Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2006-07

wrong results of function "align"

5 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Burkhard Carstens

fpc-2.1.1 r4075
linux-i386

If I understand the purpose of function align
(rtl/inc/{systemh.inc,generic.inc}) correctly, it gives wrong results when used with pointers > $8000000.

Align uses ptrint. Using ptrUint instead works.

I tried using it to align a array to 4k bounds, like this:
p:=getmem(MyAry,sizeof(MyAry)+4096); p:=align(p,4096);

IMO align($80000001,$1000) should give $80001000, but gives $80002000.

Attached is a testcase and a patch.

Reply by email

Burkhard Carstens
to Burkhard Carstens

.. there are similar problems with other align functions:

function aligntoptr in
rtl/inc/dynarr.inc
rtl/inc/variants.pp

aligntoptr($70000001) -> 70000004 //correct
aligntoptr($80000001) -> 80000008 //wrong

These are only relevant to platforms where
$FPC_REQUIRES_PROPER_ALIGNMENT

function align in
compiler/cutils.pas

align($70000001,4) -> 70000004 //correct
align($80000001,4) -> 7FFFFFFC //wrong

function aligntoptr in
rtl/objpas/typinfo.pp
seems to be the only one doing it correctly!!

Regards,
Burkhard

Reply by email

Peter Vreman
to Burkhard Carstens: fpc-2.1.1 r4075 linux-i386 If I understand the purpose of function align…
you wrote 15 lines
fpc-2.1.1 r4075 linux-i386 If I understand the purpose of function align (rtl/inc/{systemh.inc,generic.inc}) correctly, it gives wrong results when used with pointers > $8000000. Align uses ptrint. Using ptrUint instead works. I tried using it to align a array to 4k bounds, like this: p:=getmem(MyAry,sizeof(MyAry)+4096); p:=align(p,4096); IMO align($80000001,$1000) should give $80001000, but gives $80002000. Attached is a testcase and a patch.

Thanks, Patch Applied

Peter

Reply by email