[Date Prev][Date Next]
RE: nonstandard assumptions in the code
> -----Original Message-----
> From: Hallvard B Furuseth [mailto:firstname.lastname@example.org]
> 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-
> 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;
I guess that's OK. Endianness shouldn't really be a problem here since
it's a hash, we don't care about the particular sort order.
> >> * can cast function pointers to 'void *' and back
> >> (at least the threading stuff)
K&R 2nd Edition (ANSI C) p.120 "Any pointer can be cast to void * and back
again without loss of information."
> Another non-ANSI thing: LBER_OPT_ON and LDAP_OPT_ON are #defined as
> ((void*)1). There is no guarantee that this is != NULL (the *_OPT_OFF
> options). I'll install this fix unless someone protests:
K&R 2nd Edition p.102 - NULL is zero, by definition. Also stated again
in section 220.127.116.11 of the C90 spec.
-- Howard Chu
Chief Architect, Symas Corp. Director, Highland Sun
Symas: Premier OpenSource Development and Support