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.
This commit is contained in:
parent
65b2e19ef7
commit
e3e2c21639
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=131693
@ -139,9 +139,16 @@ __FBSDID("$FreeBSD$");
|
|||||||
static __inline int
|
static __inline int
|
||||||
twowords(void *p)
|
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
|
/* TCP Handling Routines
|
||||||
|
@ -139,9 +139,16 @@ __FBSDID("$FreeBSD$");
|
|||||||
static __inline int
|
static __inline int
|
||||||
twowords(void *p)
|
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
|
/* TCP Handling Routines
|
||||||
|
Loading…
Reference in New Issue
Block a user