net: net_read_uint32: assert that only 32 bit are read
On some architectures (e.g. alpha, amd64, arm64, ia64, s390x, mips64) sizeof(ulong) is 8 which made net_read_uint32 actually read too much and even returned the wrong value on big endian machines. (Note the second issue isn't that critical though, because the only architecture from the list above that uses big endian byte order is s390x ...) Also change the argument to void * because the pointer is not necessarily properly aligned. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
parent
4f2f9150b7
commit
47eb6b50bb
|
@ -269,11 +269,11 @@ static inline IPaddr_t net_read_ip(void *from)
|
|||
}
|
||||
|
||||
/* return uint32 *in network byteorder* */
|
||||
static inline uint32_t net_read_uint32(uint32_t *from)
|
||||
static inline uint32_t net_read_uint32(void *from)
|
||||
{
|
||||
ulong l;
|
||||
memcpy((void*)&l, (void*)from, sizeof(l));
|
||||
return l;
|
||||
uint32_t tmp;
|
||||
memcpy(&tmp, from, sizeof(tmp));
|
||||
return tmp;
|
||||
}
|
||||
|
||||
/* write IP *in network byteorder* */
|
||||
|
|
Loading…
Reference in New Issue