summaryrefslogtreecommitdiff
path: root/handy.h
diff options
context:
space:
mode:
authorKarl Williamson <khw@cpan.org>2021-09-06 03:21:11 -0600
committerKarl Williamson <khw@cpan.org>2021-09-07 18:22:59 -0600
commit231a6d1601b9d335d75c74dc9995dda5e7201103 (patch)
tree318f2f2fef96cd354131e736ec5e536816d597a4 /handy.h
parent75595dd289baba7e575dd7ed1d51f63834e51e7c (diff)
downloadperl-231a6d1601b9d335d75c74dc9995dda5e7201103.tar.gz
Evaluate arg to FITS_IN_8_BITS just once
This had been changed by 9555181b32f9b30122a8ea4e779c2c9916cec9f8 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.
Diffstat (limited to 'handy.h')
-rw-r--r--handy.h8
1 files changed, 4 insertions, 4 deletions
diff --git a/handy.h b/handy.h
index 52e1c6e3d8..a2dcb0daf6 100644
--- a/handy.h
+++ b/handy.h
@@ -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