[patch] Tweak _sch_test() to deal with c >= 256 correctly

Matt Hiller hiller@redhat.com
Wed Jun 12 17:16:00 GMT 2002


Some preprocessor work that I'm doing has uncovered what seems to me a
buglet in tests that are implemented with _sch_test (is_alnum(),
is_vspace(), etc.)

Am I missing something about the way that _sch_test works such that the
existing code is correct? Otherwise, okay to apply?

2002-06-12  Matt Hiller  <hiller@redhat.com>

	* safe-ctype.h (_sch_test): Return false if c >= 256 rather
	than &'ing it with 0xff and proceeding.

Index: safe-ctype.h
===================================================================
RCS file: /cvs/gcc/gcc/include/safe-ctype.h,v
retrieving revision 1.4
diff -u -p -r1.4 safe-ctype.h
--- safe-ctype.h	24 Oct 2001 19:29:16 -0000	1.4
+++ safe-ctype.h	13 Jun 2002 00:08:13 -0000
@@ -71,7 +71,8 @@ enum {
 /* Character classification.  */
 extern const unsigned short _sch_istable[256];
 
-#define _sch_test(c, bit) (_sch_istable[(c) & 0xff] & (unsigned short)(bit))
+#define _sch_test(c, bit) (((c) < 256)	 				\
+                           && (_sch_istable[(c)] & (unsigned short)(bit)))
 
 #define ISALPHA(c)  _sch_test(c, _sch_isalpha)
 #define ISALNUM(c)  _sch_test(c, _sch_isalnum)



More information about the Gcc-patches mailing list