There appears to be a bug in parts/inc/misc, though I didn't look at the
context to be sure. The isASCII() macro casts its input to U8 before
checking. That works if and only if the parameter has sizeof==1. But
if you pass 256 as the parameter, it will evaluate as true, as the cast
changes that to 0. Similarly for the isCNTRL() macro.
The attached patch mimics how I fixed this bug for handy.h in late Perl
versions (too lazy to look up which). Maybe there is a better fix; if
you can think of one, I'd be grateful if you pass it on to me.
Subject: | 0003-cpan-Devel-PPPort-parts-inc-misc-fix-isASCII-isCNTRL.patch |
From ede99cf60769489cdff1eebdcc60f7fa73120d19 Mon Sep 17 00:00:00 2001
From: Karl Williamson <public@khwilliamson.com>
Date: Tue, 27 Nov 2012 12:23:48 -0700
Subject: [PATCH 3/3] cpan/Devel-PPPort/parts/inc/misc: fix isASCII()
isCNTRL()
Prior to this patch these two macros failed on many inputs above 255
because they cast the input to the 0-255 range, losing the significant
bits.
---
cpan/Devel-PPPort/parts/inc/misc | 10 ++++++++--
1 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/cpan/Devel-PPPort/parts/inc/misc b/cpan/Devel-PPPort/parts/inc/misc
index 59c326a..6d58739 100644
--- a/cpan/Devel-PPPort/parts/inc/misc
+++ b/cpan/Devel-PPPort/parts/inc/misc
@@ -274,9 +274,15 @@ __UNDEFINED__ isXDIGIT(c) isxdigit(c)
*/
# undef isPRINT
# endif
+#ifdef HAS_QUAD
+# define WIDEST_UTYPE U64TYPE
+#else
+# define WIDEST_UTYPE U32
+#endif
+
__UNDEFINED__ isALNUMC(c) (isALPHA(c) || isDIGIT(c))
-__UNDEFINED__ isASCII(c) ((U8) (c) <= 127)
-__UNDEFINED__ isCNTRL(c) ((U8) (c) < ' ' || (c) == 127)
+__UNDEFINED__ isASCII(c) ((WIDEST_UTYPE) (c) <= 127)
+__UNDEFINED__ isCNTRL(c) ((WIDEST_UTYPE) (c) < ' ' || (c) == 127)
__UNDEFINED__ isGRAPH(c) (isALNUM(c) || isPUNCT(c))
__UNDEFINED__ isPRINT(c) (((c) >= 32 && (c) < 127))
__UNDEFINED__ isPUNCT(c) (((c) >= 33 && (c) <= 47) || ((c) >= 58 && (c) <= 64) || ((c) >= 91 && (c) <= 96) || ((c) >= 123 && (c) <= 126))
--
1.7.7.1