[uClibc]Unexpected behaviour of sscanf

Ilguiz Latypov ilatypov at superbt.com
Fri May 10 00:22:02 UTC 2002


Marko,

The default choice for ctype calls became real functions around half a
year ago.  The other choice is to use macros without relying on the static
character type table.  I think macros for ctype calls are flawed.  I
attached the correction, if anyone cares.  Nobody did half a year ago.

Ilguiz

On Fri, 10 May 2002, Marko Ebert wrote:

> 				while (isspace(scan_getc_nw(&sc)))

-------------- next part --------------
Index: ctype.h
===================================================================
RCS file: /usr/local/cvsroot/uClibc/include/ctype.h,v
retrieving revision 1.1.1.2
retrieving revision 1.3
diff -u -r1.1.1.2 -r1.3
--- ctype.h	20 Mar 2002 21:49:08 -0000	1.1.1.2
+++ ctype.h	23 Mar 2002 02:17:29 -0000	1.3
@@ -55,25 +55,32 @@
 #if defined(__USE_CTYPE_MACROS) && !defined __UCLIBC_HAS_LOCALE__
 
 /* macro definitions */
-#define isalnum(c)  (isalpha(c) || isdigit(c))
-#define isalpha(c)  (isupper(c) || islower(c))
-#define isascii(c)  (c > 0 && c <= 0x7f)
-#define isblank(c)  (c == ' ' || c == '\t')
-#define iscntrl(c)  ((c >= 0) && ((c <= 0x1F) || (c == 0x7f)))
-#define isdigit(c)  (c >= '0' && c <= '9')
-#define isgraph(c)  (c != ' ' && isprint(c))
-#define islower(c)  (c >=  'a' && c <= 'z')
-#define isprint(c)  (c >= ' ' && c <= '~')
-#define ispunct(c)  ((c > ' ' && c <= '~') && !isalnum(c))
-#define isspace(c)  (c == ' ' || c == '\f' || c == '\n' || c == '\r' ||\
-			c == '\t' || c == '\v')
-#define isupper(c)  (c >=  'A' && c <= 'Z')
-#define isxdigit(c) (isxupper(c) || isxlower(c))
-#define isxlower(c) (isdigit(c) || (c >= 'a' && c <= 'f'))
-#define isxupper(c) (isdigit(c) || (c >= 'A' && c <= 'F'))
+#define isalnum(c)  ({ int __c = c; isalpha(__c) || isdigit(__c); })
+#define isalpha(c)  ({ int __c = c; isupper(__c) || islower(__c); })
+#define isascii(c)  ({ int __c = c; __c > 0 && __c <= 0x7f; })
+#define isblank(c)  ({ int __c = c; __c == ' ' || __c == '\t'; })
+#define iscntrl(c)  ({ int __c = c; \
+	(__c >= 0) && ((__c <= 0x1F) || (__c == 0x7f)); })
+#define isdigit(c)  ({ int __c = c; __c >= '0' && __c <= '9'; })
+#define isgraph(c)  ({ int __c = c; __c != ' ' && isprint(__c); })
+#define islower(c)  ({ int __c = c; __c >=  'a' && __c <= 'z'; })
+#define isprint(c)  ({ int __c = c; __c >= ' ' && __c <= '~'; })
+#define ispunct(c)  ({ int __c = c; \
+	(__c > ' ' && __c <= '~') && !isalnum(__c); })
+#define isspace(c)  ({ int __c = c; \
+	__c == ' ' || __c == '\f' || __c == '\n' || __c == '\r' || \
+	__c == '\t' || __c == '\v'; })
+#define isupper(c)  ({ int __c = c; __c >=  'A' && __c <= 'Z'; })
+#define isxdigit(c) ({ int __c = c; isxupper(__c) || isxlower(__c); })
+#define isxlower(c) ({ int __c = c; \
+	isdigit(__c) || (__c >= 'a' && __c <= 'f'); })
+#define isxupper(c) ({ int __c = c; \
+	isdigit(__c) || (__c >= 'A' && __c <= 'F'); })
 #define toascii(c)  (c & 0x7f)
-#define tolower(c)  (isupper(c) ? ( c - 'A' + 'a') : (c))
-#define toupper(c)  (islower(c) ? (c - 'a' + 'A') : (c))
+#define tolower(c)  ({ int __c = c; \
+	isupper(__c) ? ( __c - 'A' + 'a') : (__c); })
+#define toupper(c)  ({ int __c = c; \
+	islower(__c) ? (__c - 'a' + 'A') : (__c); })
 
 #endif
 


More information about the uClibc mailing list