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
This commit is contained in:
Nick Mathewson 2004-12-08 00:42:50 +00:00
parent d7dbfd3644
commit fe6eb34a10
6 changed files with 19 additions and 14 deletions

View File

@ -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 {

View File

@ -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)) {

View File

@ -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;

View File

@ -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 == '#') {

View File

@ -2348,7 +2348,7 @@ config_parse_units(const char *val, struct unit_table_t *u, int *ok)
*ok = 1;
return v;
}
while (isspace(*cp))
while (TOR_ISSPACE(*cp))
++cp;
for ( ;u->unit;++u) {
if (!strcasecmp(u->unit, cp)) {

View File

@ -472,7 +472,7 @@ parse_http_response(const char *headers, int *code, time_t *date,
tor_assert(headers);
tor_assert(code);
while (isspace((int)*headers)) headers++; /* tolerate leading whitespace */
while (TOR_ISSPACE(*headers)) headers++; /* tolerate leading whitespace */
if (sscanf(headers, "HTTP/1.%d %d", &n1, &n2) < 2 ||
(n1 != 0 && n1 != 1) ||