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

Matt Hiller hiller@redhat.com
Tue Jun 18 14:35:00 GMT 2002


On Sun, 16 Jun 2002, Alan Modra wrote:

> On Wed, Jun 12, 2002 at 05:16:40PM -0700, Matt Hiller wrote:
> > Am I missing something about the way that _sch_test works such that the
> > existing code is correct?
> 
> The "(c) & 0xff" is to make array indexing work when "c" is a signed char.

Ah. So the correct thing is simply to add to what was there already:

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

	* safe-ctype.h (_sch_test): Check that -128 <= c <= 255 
	before proceeding; otherwise evaluate to 0.

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	18 Jun 2002 21:30:20 -0000
@@ -71,7 +71,9 @@ 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)					\
+  (-128 <= c && c <= 255					\
+   && (_sch_istable[(c) & 0xff] & (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