[or-cvs] Solaris CC freaks out if isspace and friends get anything o...
Nick Mathewson
nickm at seul.org
Wed Dec 8 00:40:05 UTC 2004
Update of /home/or/cvsroot/tor/src/common
In directory moria.mit.edu:/tmp/cvs-serv14524/src/common
Modified Files:
compat.h container.c crypto.c util.c
Log Message:
Solaris CC freaks out if isspace and friends get anything other than an int. We learned that, so we casted. But it is also a bad idea to cast a signed char to an int and expect things to work on win32. Now we cast to unsigned char, then to int, then pass to isspace. Ug
Index: compat.h
===================================================================
RCS file: /home/or/cvsroot/tor/src/common/compat.h,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- compat.h 29 Nov 2004 22:25:28 -0000 1.12
+++ compat.h 8 Dec 2004 00:40:01 -0000 1.13
@@ -82,6 +82,10 @@
CHECK_PRINTF(3,4);
int tor_vsnprintf(char *str, size_t size, const char *format, va_list args);
+#define TOR_ISSPACE(c) isspace((int)(unsigned char)(c))
+#define TOR_ISXDIGIT(c) isxdigit((int)(unsigned char)(c))
+#define TOR_ISDIGIT(c) isdigit((int)(unsigned char)(c))
+
/* ===== Time compatibility */
#if !defined(HAVE_GETTIMEOFDAY) && !defined(HAVE_STRUCT_TIMEVAL_TV_SEC)
struct timeval {
Index: container.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/common/container.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- container.c 7 Dec 2004 15:37:35 -0000 1.13
+++ container.c 8 Dec 2004 00:40:01 -0000 1.14
@@ -262,7 +262,7 @@
cp = str;
while (1) {
if (flags&SPLIT_SKIP_SPACE) {
- while (isspace((int)*cp)) ++cp;
+ while (TOR_ISSPACE(*cp)) ++cp;
}
if (max>0 && n == max-1) {
@@ -279,7 +279,7 @@
}
if (flags&SPLIT_SKIP_SPACE) {
- while (end > cp && isspace((int)*(end-1)))
+ while (end > cp && TOR_ISSPACE(*(end-1)))
--end;
}
if (end != cp || !(flags&SPLIT_IGNORE_BLANK)) {
Index: crypto.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/common/crypto.c,v
retrieving revision 1.127
retrieving revision 1.128
diff -u -d -r1.127 -r1.128
--- crypto.c 2 Dec 2004 04:33:01 -0000 1.127
+++ crypto.c 8 Dec 2004 00:40:01 -0000 1.128
@@ -974,11 +974,12 @@
crypto_pk_check_fingerprint_syntax(const char *s)
{
int i;
+ const unsigned char *cp = s;
for (i = 0; i < FINGERPRINT_LEN; ++i) {
if ((i%5) == 4) {
- if (!isspace((int)s[i])) return 0;
+ if (!TOR_ISSPACE(cp[i])) return 0;
} else {
- if (!isxdigit((int)s[i])) return 0;
+ if (!TOR_ISXDIGIT(cp[i])) return 0;
}
}
if (s[FINGERPRINT_LEN]) return 0;
Index: util.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/common/util.c,v
retrieving revision 1.194
retrieving revision 1.195
diff -u -d -r1.194 -r1.195
--- util.c 6 Dec 2004 22:39:10 -0000 1.194
+++ util.c 8 Dec 2004 00:40:01 -0000 1.195
@@ -331,8 +331,8 @@
const char *eat_whitespace(const char *s) {
tor_assert(s);
- while (isspace((int)*s) || *s == '#') {
- while (isspace((int)*s))
+ while (TOR_ISSPACE(*s) || *s == '#') {
+ while (TOR_ISSPACE(*s))
s++;
if (*s == '#') { /* read to a \n or \0 */
while (*s && *s != '\n')
@@ -358,7 +358,7 @@
const char *find_whitespace(const char *s) {
tor_assert(s);
- while (*s && !isspace((int)*s) && *s != '#')
+ while (*s && !TOR_ISSPACE(*s) && *s != '#')
s++;
return s;
@@ -427,8 +427,8 @@
tor_assert(base <= 10);
r = (uint64_t)_atoi64(s);
endptr = (char*)s;
- while (isspace(*endptr)) endptr++;
- while (isdigit(*endptr)) endptr++;
+ while (TOR_ISSPACE(*endptr)) endptr++;
+ while (TOR_ISDIGIT(*endptr)) endptr++;
#else
r = (uint64_t)_strtoui64(s, &endptr, base);
#endif
@@ -936,7 +936,7 @@
*key_out = *value_out = key = val = NULL;
/* Skip until the first keyword. */
while (1) {
- while (isspace(*line))
+ while (TOR_ISSPACE(*line))
++line;
if (*line == '#') {
while (*line && *line != '\n')
@@ -953,7 +953,7 @@
/* Skip until the next space. */
key = line;
- while (*line && !isspace(*line) && *line != '#')
+ while (*line && !TOR_ISSPACE(*line) && *line != '#')
++line;
/* Skip until the value */
@@ -969,7 +969,7 @@
else {
cp = line-1;
}
- while (cp>=val && isspace(*cp))
+ while (cp>=val && TOR_ISSPACE(*cp))
*cp-- = '\0';
if (*line == '#') {
More information about the tor-commits
mailing list