From: Aurelien Jacobs Date: Mon, 30 Dec 2013 18:23:54 +0000 (+0100) Subject: fix endian neutral helper macro to return an integer type X-Git-Tag: libsigrok-0.3.0~358 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=79a1176b3f027f0d29628d98a69c9e97864ed052;p=libsigrok.git fix endian neutral helper macro to return an integer type --- diff --git a/libsigrok-internal.h b/libsigrok-internal.h index b3eeb8db..722441b3 100644 --- a/libsigrok-internal.h +++ b/libsigrok-internal.h @@ -55,36 +55,36 @@ * @param x a pointer to the input memory * @return the corresponding integer */ -#define RB16(x) ((((const uint8_t*)(x))[0] << 8) | \ - ((const uint8_t*)(x))[1]) +#define RB16(x) (((unsigned)((const uint8_t*)(x))[0] << 8) | \ + (unsigned)((const uint8_t*)(x))[1]) /** * Read a 16 bits little endian integer out of memory. * @param x a pointer to the input memory * @return the corresponding integer */ -#define RL16(x) ((((const uint8_t*)(x))[1] << 8) | \ - ((const uint8_t*)(x))[0]) +#define RL16(x) (((unsigned)((const uint8_t*)(x))[1] << 8) | \ + (unsigned)((const uint8_t*)(x))[0]) /** * Read a 32 bits big endian integer out of memory. * @param x a pointer to the input memory * @return the corresponding integer */ -#define RB32(x) ((((const uint8_t*)(x))[0] << 24) | \ - (((const uint8_t*)(x))[1] << 16) | \ - (((const uint8_t*)(x))[2] << 8) | \ - ((const uint8_t*)(x))[3]) +#define RB32(x) (((unsigned)((const uint8_t*)(x))[0] << 24) | \ + ((unsigned)((const uint8_t*)(x))[1] << 16) | \ + ((unsigned)((const uint8_t*)(x))[2] << 8) | \ + (unsigned)((const uint8_t*)(x))[3]) /** * Read a 32 bits little endian integer out of memory. * @param x a pointer to the input memory * @return the corresponding integer */ -#define RL32(x) ((((const uint8_t*)(x))[3] << 24) | \ - (((const uint8_t*)(x))[2] << 16) | \ - (((const uint8_t*)(x))[1] << 8) | \ - ((const uint8_t*)(x))[0]) +#define RL32(x) (((unsigned)((const uint8_t*)(x))[3] << 24) | \ + ((unsigned)((const uint8_t*)(x))[2] << 16) | \ + ((unsigned)((const uint8_t*)(x))[1] << 8) | \ + (unsigned)((const uint8_t*)(x))[0]) /* Portability fixes for FreeBSD. */ #ifdef __FreeBSD__