1
1
mirror of https://github.com/BLAKE2/BLAKE2 synced 2024-11-07 14:49:17 +01:00

Update cast of load16

Bitwise operations promote the cast to uint16_t to int. So to be consistent, first cast to uint to keep unsignedness and prevent implicit promotion. Then cast back to uint16_t after all bitwise operations are completed. 

This prevents compiler warnings, unneccessary casts and in the case of right shifting (not the case here) unexpected behaviour.
This commit is contained in:
mjvk 2018-05-09 11:47:06 +01:00 committed by GitHub
parent ca4c89314a
commit cf068aafd6
Signed by: GitHub
GPG Key ID: 4AEE18F83AFDEB23

@ -72,8 +72,8 @@ static BLAKE2_INLINE uint16_t load16( const void *src )
return w;
#else
const uint8_t *p = ( const uint8_t * )src;
return (( uint16_t )( p[0] ) << 0) |
(( uint16_t )( p[1] ) << 8) ;
return ( uint16_t )((( uint32_t )( p[0] ) << 0) |
(( uint32_t )( p[1] ) << 8));
#endif
}