Re: [PATCH] bswap: convert to unsigned before shifting in get_be32

2017-07-15 Thread Ramsay Jones
On 15/07/17 20:11, René Scharfe wrote: > The pointer p is dereferenced and we get an unsigned char. Before > shifting it's automatically promoted to int. Left-shifting a signed > 32-bit value bigger than 127 by 24 places is undefined. Explicitly > convert to a 32-bit unsigned type to avoid

[PATCH] bswap: convert to unsigned before shifting in get_be32

2017-07-15 Thread René Scharfe
The pointer p is dereferenced and we get an unsigned char. Before shifting it's automatically promoted to int. Left-shifting a signed 32-bit value bigger than 127 by 24 places is undefined. Explicitly convert to a 32-bit unsigned type to avoid undefined behaviour if the highest bit is set.