[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
casts in glibc <ctype.h> cause standards-conformance bug
From: |
Paul Eggert |
Subject: |
casts in glibc <ctype.h> cause standards-conformance bug |
Date: |
Thu, 5 Dec 2002 16:19:14 -0800 |
The C Standard requires a diagnostic for the following program:
#include <ctype.h>
int
main (void)
{
return isalpha ("");
}
due to the type clash in the argument to isalpha.
However, in my Debian GNU/Linux box there is no diagnostic, and from
code inspection it appears that the problem remains in glibc 2.3.1.
Here is an untested patch for this particular problem. I suspect that
other similar ones are lurking in other function macros that cast
their arguments.
2002-12-05 Paul Eggert <address@hidden>
* ctype/ctype.h (__ctype_int): New function.
(__isctype, __isctype_l): Use it so that a diagnostic is generated
for e.g. `isalpha ("")', as the C standard requires.
(_tolower, _toupper): Likewise, except here it's an SVID req't.
--- ctype/ctype.h 2002-09-02 11:48:00.000000000 -0700
+++ /tmp/ctype.h 2002-12-05 15:31:09.000000000 -0800
@@ -85,8 +85,10 @@
extern __const __int32_t **__ctype_toupper_loc (void)
__attribute__ ((__const));
+static inline int __ctype_int (int __c) { return __c; }
+
#define __isctype(c, type) \
- ((*__ctype_b_loc ())[(int) (c)] & (unsigned short int) type)
+ ((*__ctype_b_loc ())[__ctype_int (c)] & (unsigned short int) type)
#define __isascii(c) (((c) & ~0x7f) == 0) /* If C is a 7 bit
value. */
#define __toascii(c) ((c) & 0x7f) /* Mask off high bits.
*/
@@ -209,8 +211,8 @@
# define isascii(c) __isascii (c)
# define toascii(c) __toascii (c)
-# define _tolower(c) ((int) (*__ctype_tolower_loc ())[(int) (c)])
-# define _toupper(c) ((int) (*__ctype_toupper_loc ())[(int) (c)])
+# define _tolower(c) ((int) (*__ctype_tolower_loc ())[__ctype_int (c)])
+# define _toupper(c) ((int) (*__ctype_toupper_loc ())[__ctype_int (c)])
# endif
#endif /* Not __NO_CTYPE. */
@@ -235,7 +237,7 @@
/* These definitions are similar to the ones above but all functions
take as an argument a handle for the locale which shall be used. */
# define __isctype_l(c, type, locale) \
- ((locale)->__ctype_b[(int) (c)] & (unsigned short int) type)
+ ((locale)->__ctype_b[__ctype_int (c)] & (unsigned short int) type)
# define __exctype_l(name) \
extern int name (int, __locale_t) __THROW
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- casts in glibc <ctype.h> cause standards-conformance bug,
Paul Eggert <=