diff options
author | Karl Williamson <khw@khw-desktop.(none)> | 2010-04-19 20:05:31 -0600 |
---|---|---|
committer | Rafael Garcia-Suarez <rgs@consttype.org> | 2010-04-26 10:20:09 +0200 |
commit | 353c9b6f16dec626f888894e7df6f8819303bd11 (patch) | |
tree | 1dafddd3bb9a82a2f00f56b4c776e1095c371c20 /handy.h | |
parent | eae68503d2ac04e4cb67e7304895150dea94c348 (diff) | |
download | perl-353c9b6f16dec626f888894e7df6f8819303bd11.tar.gz |
Make sure isCNTRL and isASCII work on signed chars
Prior to this patch, there is a potential bug in these two macros, in
which, if they are called with a signed character outside the ASCII
range, it will be negative and they always returned true for negative.
Casting the parameter to an unsigned should fix that by having it be
interpreted as a number above the ASCII range.
Diffstat (limited to 'handy.h')
-rw-r--r-- | handy.h | 9 |
1 files changed, 7 insertions, 2 deletions
@@ -463,6 +463,11 @@ Converts the specified character to lowercase. Characters outside the US-ASCII (Basic Latin) range are viewed as not having any case. =cut + +NOTE: Since some of these are macros, there is no check in those that the +parameter is a char or U8. This means that if called with a larger width +parameter, casts can silently truncate and yield wrong results. + */ #define isALNUM(c) (isALPHA(c) || isDIGIT(c) || (c) == '_') @@ -504,8 +509,8 @@ US-ASCII (Basic Latin) range are viewed as not having any case. # define isUPPER(c) ((c) >= 'A' && (c) <= 'Z') # define isLOWER(c) ((c) >= 'a' && (c) <= 'z') # define isALNUMC(c) (isALPHA(c) || isDIGIT(c)) -# define isASCII(c) ((c) <= 127) -# define isCNTRL(c) ((c) < ' ' || (c) == 127) +# define isASCII(c) ((U8) (c) <= 127) +# define isCNTRL(c) ((U8) (c) < ' ' || (c) == 127) # define isGRAPH(c) (isALNUM(c) || isPUNCT(c)) # define isPRINT(c) (((c) >= 32 && (c) < 127)) # define isPUNCT(c) (((c) >= 33 && (c) <= 47) || ((c) >= 58 && (c) <= 64) || ((c) >= 91 && (c) <= 96) || ((c) >= 123 && (c) <= 126)) |