summaryrefslogtreecommitdiff
path: root/handy.h
diff options
context:
space:
mode:
authorKarl Williamson <khw@cpan.org>2016-07-28 11:40:50 -0600
committerKarl Williamson <khw@cpan.org>2016-07-28 12:01:42 -0600
commit6c5b02ac7a9ff1c91f2ca46bedd89ba9012bb34f (patch)
treebbd9905b62ab03daef5e1e5e9d3bfa83fbed4b80 /handy.h
parent6f39eb491a3f31125ff9f8ab6b6a53e62255ac6c (diff)
downloadperl-6c5b02ac7a9ff1c91f2ca46bedd89ba9012bb34f.tar.gz
handy.h: Generate compile error if macros called wrong
This extends the mechanism we added in 5.24 to more macros to make sure that a macro is called with an integer and not a pointer. It adds a "| 0" to the macro parameter, which is illegal if the parameter is a pointer.
Diffstat (limited to 'handy.h')
-rw-r--r--handy.h5
1 files changed, 4 insertions, 1 deletions
diff --git a/handy.h b/handy.h
index b1b50ff637..0f4b7f845c 100644
--- a/handy.h
+++ b/handy.h
@@ -910,7 +910,10 @@ patched there. The file as of this writing is cpan/Devel-PPPort/parts/inc/misc
* of operands. Well, they are, but that is kind of the point.
*/
#ifndef __COVERITY__
-#define FITS_IN_8_BITS(c) ((sizeof(c) == 1) || !(((WIDEST_UTYPE)(c)) & ~0xFF))
+ /* 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)(c | 0)) & ~0xFF))
#else
#define FITS_IN_8_BITS(c) (1)
#endif