Skip to content

Commit

Permalink
Evaluate arg to FITS_IN_8_BITS just once
Browse files Browse the repository at this point in the history
This had been changed by 9555181 to
evaluating multiple times.

(sizeof() also is called with the parameter, but that doesn't actually
evaluate the parameter.)

The previous version of this commit used a comparison with 0xFF, but gcc
is smart enough to realise that `comparison is always true due to limited
range of data type`, but not smart enough to realise that the sizeof makes
that code unreachable. Hence with -Wtype-limits we get thousands of warnings.

Using >> defeats the warnings.
  • Loading branch information
khwilliamson committed Sep 8, 2021
1 parent 75595dd commit 231a6d1
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions handy.h
Expand Up @@ -1447,10 +1447,10 @@ or casts
* of operands. Well, they are, but that is kind of the point.
*/
#ifndef __COVERITY__
/* The '| 0' part ensures a compiler error if c is not integer (like e.g., a
* pointer) */
# define FITS_IN_8_BITS(c) ( (sizeof(c) == 1) \
|| ((WIDEST_UTYPE) ASSERT_NOT_PTR(c)) == ((U8)(c)))
/* The '| 0' part in ASSERT_NOT_PTR ensures a compiler error if c is not
* integer (like e.g., a pointer) */
# define FITS_IN_8_BITS(c) ( (sizeof(c) == 1) \
|| (((WIDEST_UTYPE) ASSERT_NOT_PTR(c)) >> 8) == 0)
#else
# define FITS_IN_8_BITS(c) (1)
#endif
Expand Down

0 comments on commit 231a6d1

Please sign in to comment.