Date: Mon, 05 Jul 2004 18:44:21 +0200 From: des@des.no (=?iso-8859-1?q?Dag-Erling_Sm=F8rgrav?=) To: David Malone <dwmalone@maths.tcd.ie> Cc: current@freebsd.org Subject: Re: recent libalias changes Message-ID: <xzpoemu9zfe.fsf@dwp.des.no> In-Reply-To: <xzpsmc6a02c.fsf@dwp.des.no> (Dag-Erling =?iso-8859-1?q?Sm=F8rgrav's?= message of "Mon, 05 Jul 2004 18:30:35 %2B0200") References: <20040705133820.GA9159@stud.fit.vutbr.cz> <xzp1xjqbhee.fsf@dwp.des.no> <20040705161059.GA52584@walton.maths.tcd.ie> <xzpsmc6a02c.fsf@dwp.des.no>
next in thread | previous in thread | raw e-mail | index | archive | help
--=-=-= Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable des@des.no (Dag-Erling Sm=F8rgrav) writes: > David Malone <dwmalone@maths.tcd.ie> writes: > > With Divacky's help we localised his problem to alias.c. The twowords > > function breaks the strick aliasing rule, try replacing it with: > > [...] > oh no you don't - this is not endian-clean. Please try the attached patch. DES --=20 Dag-Erling Sm=F8rgrav - des@des.no --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=twowords.diff Index: alias.c =================================================================== RCS file: /home/ncvs/src/lib/libalias/alias.c,v retrieving revision 1.46 diff -u -r1.46 alias.c --- alias.c 5 Jul 2004 11:10:57 -0000 1.46 +++ alias.c 5 Jul 2004 16:42:00 -0000 @@ -139,9 +139,16 @@ static __inline int twowords(void *p) { - u_short *s = p; + uint8_t *c = p; - return (s[0] + s[1]); +#if BYTE_ORDER == LITTLE_ENDIAN + uint16_t s1 = ((uint16_t)c[1] << 8) + (uint16_t)c[0]; + uint16_t s2 = ((uint16_t)c[3] << 8) + (uint16_t)c[2]; +#else + uint16_t s1 = ((uint16_t)c[0] << 8) + (uint16_t)c[1]; + uint16_t s2 = ((uint16_t)c[2] << 8) + (uint16_t)c[3]; +#endif + return (s1 + s2); } /* TCP Handling Routines --=-=-=--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?xzpoemu9zfe.fsf>