Skip to content

Commit

Permalink
Update cast of load16
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mjvankampen committed May 9, 2018
1 parent ca4c893 commit cf068aa
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions sse/blake2-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit cf068aa

Please sign in to comment.