From 15b31aa05a681edaed2d190c0f921fb644c152fb Mon Sep 17 00:00:00 2001 From: "Andrey A. Chernov" Date: Fri, 3 Nov 1995 12:25:14 +0000 Subject: [PATCH] Fix isspecial/isphonogram, they was swapped Remove EOF hack, now it is recognized per ANSI/POSIX Add upper bounds check Handle all negative chars inside locale functions --- include/_ctype.h | 31 +++++++++++++------------------ include/ctype.h | 31 +++++++++++++------------------ 2 files changed, 26 insertions(+), 36 deletions(-) diff --git a/include/_ctype.h b/include/_ctype.h index 157134eea879..963a4d4416b1 100644 --- a/include/_ctype.h +++ b/include/_ctype.h @@ -111,9 +111,9 @@ __END_DECLS #define ishexnumber(c) __istype((c), _X) #define isideogram(c) __istype((c), _I) #define isnumber(c) __istype((c), _D) -#define isphonogram(c) __istype((c), _T) +#define isphonogram(c) __istype((c), _Q) #define isrune(c) __istype((c), 0xFFFFFF00L) -#define isspecial(c) __istype((c), _Q) +#define isspecial(c) __istype((c), _T) #endif /* See comments in about _BSD_RUNE_T_. */ @@ -141,37 +141,32 @@ __END_DECLS static __inline int __istype(_BSD_RUNE_T_ _c, unsigned long _f) { - if (_c < 0) - _c = (unsigned char) _c; - return((((_c & _CRMASK) ? ___runetype(_c) : - _CurrentRuneLocale->runetype[_c]) & _f) ? 1 : 0); + return (_c < 0 || _c & _CRMASK) ? !!(___runetype(_c) & _f) : + (_c >= _CACHED_RUNES) ? 0 : + !!(_CurrentRuneLocale->runetype[_c] & _f); } static __inline int __isctype(_BSD_RUNE_T_ _c, unsigned long _f) { - if (_c < 0) - _c = (unsigned char) _c; - return((((_c & _CRMASK) ? 0 : - _DefaultRuneLocale.runetype[_c]) & _f) ? 1 : 0); + return (_c < 0 || _c >= _CACHED_RUNES) ? 0 : + !!(_DefaultRuneLocale.runetype[_c] & _f); } static __inline _BSD_RUNE_T_ __toupper(_BSD_RUNE_T_ _c) { - if (_c < 0) - _c = (unsigned char) _c; - return((_c & _CRMASK) ? - ___toupper(_c) : _CurrentRuneLocale->mapupper[_c]); + return (_c < 0 || _c & _CRMASK) ? ___toupper(_c) : + (_c >= _CACHED_RUNES) ? _c : + _CurrentRuneLocale->mapupper[_c]; } static __inline _BSD_RUNE_T_ __tolower(_BSD_RUNE_T_ _c) { - if (_c < 0) - _c = (unsigned char) _c; - return((_c & _CRMASK) ? - ___tolower(_c) : _CurrentRuneLocale->maplower[_c]); + return (_c < 0 || _c & _CRMASK) ? ___tolower(_c) : + (_c >= _CACHED_RUNES) ? _c : + _CurrentRuneLocale->maplower[_c]; } #else /* not using inlines */ diff --git a/include/ctype.h b/include/ctype.h index 157134eea879..963a4d4416b1 100644 --- a/include/ctype.h +++ b/include/ctype.h @@ -111,9 +111,9 @@ __END_DECLS #define ishexnumber(c) __istype((c), _X) #define isideogram(c) __istype((c), _I) #define isnumber(c) __istype((c), _D) -#define isphonogram(c) __istype((c), _T) +#define isphonogram(c) __istype((c), _Q) #define isrune(c) __istype((c), 0xFFFFFF00L) -#define isspecial(c) __istype((c), _Q) +#define isspecial(c) __istype((c), _T) #endif /* See comments in about _BSD_RUNE_T_. */ @@ -141,37 +141,32 @@ __END_DECLS static __inline int __istype(_BSD_RUNE_T_ _c, unsigned long _f) { - if (_c < 0) - _c = (unsigned char) _c; - return((((_c & _CRMASK) ? ___runetype(_c) : - _CurrentRuneLocale->runetype[_c]) & _f) ? 1 : 0); + return (_c < 0 || _c & _CRMASK) ? !!(___runetype(_c) & _f) : + (_c >= _CACHED_RUNES) ? 0 : + !!(_CurrentRuneLocale->runetype[_c] & _f); } static __inline int __isctype(_BSD_RUNE_T_ _c, unsigned long _f) { - if (_c < 0) - _c = (unsigned char) _c; - return((((_c & _CRMASK) ? 0 : - _DefaultRuneLocale.runetype[_c]) & _f) ? 1 : 0); + return (_c < 0 || _c >= _CACHED_RUNES) ? 0 : + !!(_DefaultRuneLocale.runetype[_c] & _f); } static __inline _BSD_RUNE_T_ __toupper(_BSD_RUNE_T_ _c) { - if (_c < 0) - _c = (unsigned char) _c; - return((_c & _CRMASK) ? - ___toupper(_c) : _CurrentRuneLocale->mapupper[_c]); + return (_c < 0 || _c & _CRMASK) ? ___toupper(_c) : + (_c >= _CACHED_RUNES) ? _c : + _CurrentRuneLocale->mapupper[_c]; } static __inline _BSD_RUNE_T_ __tolower(_BSD_RUNE_T_ _c) { - if (_c < 0) - _c = (unsigned char) _c; - return((_c & _CRMASK) ? - ___tolower(_c) : _CurrentRuneLocale->maplower[_c]); + return (_c < 0 || _c & _CRMASK) ? ___tolower(_c) : + (_c >= _CACHED_RUNES) ? _c : + _CurrentRuneLocale->maplower[_c]; } #else /* not using inlines */