Rogério Brito <[EMAIL PROTECTED]> writes:

>> A construct like that is used several times with i=0 to get
>> srcOffs[-1]. The problem here is "UInt32 i". When i=0 the i-1 gives
>> 4294967295 and not -1.
>
> Agreed here, since we are using two's complement (the most common way of
> storing integers on modern machines).
>
>> In 32bit that results in the same because the array pointer overflows.
>
> Do you mean that using 0xffffffff as an index in an array (on 32 bit
> arches) does the same thing as using -1? Never heard of that before, but
> nice to know (and to test here after writing this e-mail).

There is only one add command which works for both signed and unsigned
integers in the cpu. That is the beauty of two's complement. But even
without that adding unsigned 0xffffffff to an address will decrease
that address by one. It adds (0x100000000 - 1). 

>> But in 64bit it happily accesses element 4294967295 and segfaults. By
>> changing i to int the desired [-1] is used.
>
> Agreed again. We do need i to be signed if -1 is to be used (which I'm
> not exactly sure that is a proper thing to do).

Think of the following code:

UInt32 offsets[10];

void foo(UInt32 *off) {
     off[-1];
}

foo(&offstes[5]);

An index of -1 can be totaly valid.

> P.S.: Are you willing to help package this cleaning up the code and
> possibly feeding the patches upstream?

Not really. I don't use any HFS. I just had some time to kill.

> P.P.S.: I saw that you are a co-maintainer of ia32-libs together with
> Bdale Garbee. What a small world! :-)

MfG
        Goswin



--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to