diff options
author | Nick Mathewson <nickm@torproject.org> | 2004-12-08 00:42:50 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2004-12-08 00:42:50 +0000 |
commit | fe6eb34a10ccfc2ececbcc7459d0a1fb23b9b021 (patch) | |
tree | 806b089836d892e3024af375d8c0e95a9ef8fe00 /src/common | |
parent | d7dbfd3644dac410cb4ee558f31b514ca3689afc (diff) | |
download | tor-fe6eb34a10ccfc2ececbcc7459d0a1fb23b9b021.tar.gz tor-fe6eb34a10ccfc2ececbcc7459d0a1fb23b9b021.zip |
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
svn:r3120
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/compat.h | 4 | ||||
-rw-r--r-- | src/common/container.c | 4 | ||||
-rw-r--r-- | src/common/crypto.c | 5 | ||||
-rw-r--r-- | src/common/util.c | 16 |
4 files changed, 17 insertions, 12 deletions
diff --git a/src/common/compat.h b/src/common/compat.h index 6b718c2f53..20c243e500 100644 --- a/src/common/compat.h +++ b/src/common/compat.h @@ -82,6 +82,10 @@ int tor_snprintf(char *str, size_t size, const char *format, ...) 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 { diff --git a/src/common/container.c b/src/common/container.c index 69d3d2731e..0055fcb476 100644 --- a/src/common/container.c +++ b/src/common/container.c @@ -262,7 +262,7 @@ int smartlist_split_string(smartlist_t *sl, const char *str, const char *sep, 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 @@ int smartlist_split_string(smartlist_t *sl, const char *str, const char *sep, } 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)) { diff --git a/src/common/crypto.c b/src/common/crypto.c index 6d4533b5da..eaf438e835 100644 --- a/src/common/crypto.c +++ b/src/common/crypto.c @@ -974,11 +974,12 @@ int 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; diff --git a/src/common/util.c b/src/common/util.c index 7621452448..162fae680f 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -331,8 +331,8 @@ int strcasecmpend(const char *s1, const char *s2) 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 *eat_whitespace_no_nl(const char *s) { 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_parse_uint64(const char *s, int base, uint64_t min, 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 @@ parse_line_from_str(char *line, char **key_out, char **value_out) *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 @@ parse_line_from_str(char *line, char **key_out, char **value_out) /* 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 @@ parse_line_from_str(char *line, char **key_out, char **value_out) else { cp = line-1; } - while (cp>=val && isspace(*cp)) + while (cp>=val && TOR_ISSPACE(*cp)) *cp-- = '\0'; if (*line == '#') { |