aboutsummaryrefslogtreecommitdiff
path: root/lib/libalias
diff options
context:
space:
mode:
authorDag-Erling Smørgrav <des@FreeBSD.org>2004-07-06 09:22:18 +0000
committerDag-Erling Smørgrav <des@FreeBSD.org>2004-07-06 09:22:18 +0000
commite3e2c216398b34e94a5d10701c8a25745cb910e0 (patch)
tree07a2be27b9b9801ab65c5c3c5c01c3f0a04290a9 /lib/libalias
parent65b2e19ef7649366564fd9fda8c27d7df1d75a27 (diff)
downloadsrc-e3e2c216398b34e94a5d10701c8a25745cb910e0.tar.gz
src-e3e2c216398b34e94a5d10701c8a25745cb910e0.zip
Rewrite twowords() to access its argument through a char pointer and not
a short pointer. The previous implementation seems to be in a gray zone of the C standard, and GCC generates incorrect code for it at -O2 or higher on some platforms.
Notes
Notes: svn path=/head/; revision=131693
Diffstat (limited to 'lib/libalias')
-rw-r--r--lib/libalias/alias.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/lib/libalias/alias.c b/lib/libalias/alias.c
index 832190057160..6acf03b01d44 100644
--- a/lib/libalias/alias.c
+++ b/lib/libalias/alias.c
@@ -139,9 +139,16 @@ __FBSDID("$FreeBSD$");
static __inline int
twowords(void *p)
{
- u_short *s = p;
-
- return (s[0] + s[1]);
+ uint8_t *c = p;
+
+#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