[Date Prev][Date Next]
[Chronological]
[Thread]
[Top]
RE: nonstandard assumptions in the code
> -----Original Message-----
> From: Hallvard B Furuseth [mailto:h.b.furuseth@usit.uio.no]
> Kurt D. Zeilenga writes:
> >At 11:01 AM 5/30/2003, Hallvard B Furuseth wrote:
> >>
> >> Here are the nonstandard assumptions I have found.
> >> (...)
>
>
> >> * no padding bits in 'unsigned int'
> >> (required by back-bdb/dbcache.c:bdb_db_hash() - don't know why)
> >> (...)
> > These should be fixed.
>
> Howard, this is your code, from when you fixed ITS#1726. Something
> about endianness, perhaps? If not, we can use this function body,
> roughly from my original patch. I have dropped the ugly if-test for
> whether or not memcpy can be used, since I doubt the code is
> that time-
> critical.
>
> {
> u_int32_t i, ret = 0;
>
> if ( length > sizeof(u_int32_t) )
> length = sizeof(u_int32_t);
>
> for( i = 0; i < length; i++ )
> ret = (ret << 8) + ((const unsigned char *)bytes)[i];
> return ret;
> }
This code reverses the byte-order of the hash on little-endian machines,
which makes the hash databases in HEAD incompatible with RE22.
I note that the BDB configure script demands that sizeof(u_int32_t) == 4,
so I don't see any point in accomodating padding bits here. Whether they
exist or not at the machine level should be invisible at the C level, if
the compiler is going to claim that sizeof(u_int32_t) == 4. I think the
previous code was perfectly fine and we should revert.
-- Howard Chu
Chief Architect, Symas Corp. Director, Highland Sun
http://www.symas.com http://highlandsun.com/hyc
Symas: Premier OpenSource Development and Support