From 82cafdeb0afbdd287f37f690cf9d18ea4e408431 Mon Sep 17 00:00:00 2001 From: millert Date: Mon, 12 Jan 2015 14:36:48 +0000 Subject: [PATCH] Use proper casts for ctype functions. This is already fixed in nsd trunk. OK doug@ --- usr.sbin/nsd/compat/b64_pton.c | 6 ++--- usr.sbin/nsd/compat/inet_aton.c | 10 ++++---- usr.sbin/nsd/compat/strptime.c | 8 +++--- usr.sbin/nsd/dns.c | 4 +-- usr.sbin/nsd/nsd.c | 4 +-- usr.sbin/nsd/rdata.c | 12 ++++----- usr.sbin/nsd/remote.c | 4 +-- usr.sbin/nsd/tsig.c | 4 +-- usr.sbin/nsd/util.c | 8 +++--- usr.sbin/nsd/zlexer.lex | 2 +- usr.sbin/nsd/zonec.c | 44 ++++++++++++++++----------------- 11 files changed, 52 insertions(+), 54 deletions(-) diff --git a/usr.sbin/nsd/compat/b64_pton.c b/usr.sbin/nsd/compat/b64_pton.c index 08506040b64..0e4aafceb35 100644 --- a/usr.sbin/nsd/compat/b64_pton.c +++ b/usr.sbin/nsd/compat/b64_pton.c @@ -144,18 +144,16 @@ static void b64_initialize_rmap () { int i; - char ch; /* Null: end of string, stop parsing */ b64rmap[0] = b64rmap_end; for (i = 1; i < 256; ++i) { - ch = (char)i; /* Whitespaces */ - if (isspace(ch)) + if (isspace(i)) b64rmap[i] = b64rmap_space; /* Padding: stop parsing */ - else if (ch == Pad64) + else if (i == Pad64) b64rmap[i] = b64rmap_end; /* Non-base64 char */ else diff --git a/usr.sbin/nsd/compat/inet_aton.c b/usr.sbin/nsd/compat/inet_aton.c index 7eb8e623d95..430f9b03d4f 100644 --- a/usr.sbin/nsd/compat/inet_aton.c +++ b/usr.sbin/nsd/compat/inet_aton.c @@ -99,7 +99,7 @@ inet_aton(const char *cp, struct in_addr *addr) * Values are specified as for C: * 0x=hex, 0=octal, isdigit=decimal. */ - if (!isdigit((int)c)) + if (!isdigit((unsigned char)c)) return (0); val = 0; base = 10; if (c == '0') { @@ -110,12 +110,12 @@ inet_aton(const char *cp, struct in_addr *addr) base = 8; } for (;;) { - if (isascii((int)c) && isdigit((int)c)) { + if (isascii((unsigned char)c) && isdigit((unsigned char)c)) { val = (val * base) + (c - '0'); c = *++cp; - } else if (base == 16 && isascii((int)c) && isxdigit((int)c)) { + } else if (base == 16 && isascii((unsigned char)c) && isxdigit((unsigned char)c)) { val = (val << 4) | - (c + 10 - (islower((int)c) ? 'a' : 'A')); + (c + 10 - (islower((unsigned char)c) ? 'a' : 'A')); c = *++cp; } else break; @@ -137,7 +137,7 @@ inet_aton(const char *cp, struct in_addr *addr) /* * Check for trailing characters. */ - if (c != '\0' && (!isascii((int)c) || !isspace((int)c))) + if (c != '\0' && (!isascii((unsigned char)c) || !isspace((unsigned char)c))) return (0); /* * Concoct the address according to diff --git a/usr.sbin/nsd/compat/strptime.c b/usr.sbin/nsd/compat/strptime.c index 4ec96c12cef..e6eb375918f 100644 --- a/usr.sbin/nsd/compat/strptime.c +++ b/usr.sbin/nsd/compat/strptime.c @@ -91,7 +91,7 @@ str2int(const char **buf, int max) { int ret=0, count=0; - while (*buf[0] != '\0' && isdigit(*buf[0]) && count arg) + while(isspace((unsigned char)*as) && as > arg) as--; as[0]=0; return 1; diff --git a/usr.sbin/nsd/tsig.c b/usr.sbin/nsd/tsig.c index 1844e98d9e1..316f477894d 100644 --- a/usr.sbin/nsd/tsig.c +++ b/usr.sbin/nsd/tsig.c @@ -154,8 +154,8 @@ int tsig_strlowercmp(const char* str1, const char* str2) { while (str1 && str2 && *str1 != '\0' && *str2 != '\0') { - if(tolower((int)*str1) != tolower((int)*str2)) { - if(tolower((int)*str1) < tolower((int)*str2)) + if(tolower((unsigned char)*str1) != tolower((unsigned char)*str2)) { + if(tolower((unsigned char)*str1) < tolower((unsigned char)*str2)) return -1; return 1; } diff --git a/usr.sbin/nsd/util.c b/usr.sbin/nsd/util.c index 7d93f54b55b..7af07d0c65e 100644 --- a/usr.sbin/nsd/util.c +++ b/usr.sbin/nsd/util.c @@ -553,7 +553,7 @@ hex_pton(const char* src, uint8_t* target, size_t targsize) return -1; } while(*src) { - if(!isxdigit((int)src[0]) || !isxdigit((int)src[1])) + if(!isxdigit((unsigned char)src[0]) || !isxdigit((unsigned char)src[1])) return -1; *t++ = hexdigit_to_int(src[0]) * 16 + hexdigit_to_int(src[1]) ; @@ -658,7 +658,7 @@ b32_pton(const char *src, uint8_t *target, size_t tsize) if(p+5 >= tsize*8) return -1; - if(isspace(ch)) + if(isspace((unsigned char)ch)) continue; if(ch >= '0' && ch <= '9') @@ -690,13 +690,13 @@ strip_string(char *str) char *start = str; char *end = str + strlen(str) - 1; - while (isspace(*start)) + while (isspace((unsigned char)*start)) ++start; if (start > end) { /* Completely blank. */ str[0] = '\0'; } else { - while (isspace(*end)) + while (isspace((unsigned char)*end)) --end; *++end = '\0'; diff --git a/usr.sbin/nsd/zlexer.lex b/usr.sbin/nsd/zlexer.lex index 56ad724e108..90a1df3741c 100644 --- a/usr.sbin/nsd/zlexer.lex +++ b/usr.sbin/nsd/zlexer.lex @@ -346,7 +346,7 @@ zoctet(char *text) if (s[0] != '\\') { /* Ordinary character. */ *p = *s; - } else if (isdigit((int)s[1]) && isdigit((int)s[2]) && isdigit((int)s[3])) { + } else if (isdigit((unsigned char)s[1]) && isdigit((unsigned char)s[2]) && isdigit((unsigned char)s[3])) { /* \DDD escape. */ int val = (hexdigit_to_int(s[1]) * 100 + hexdigit_to_int(s[2]) * 10 + diff --git a/usr.sbin/nsd/zonec.c b/usr.sbin/nsd/zonec.c index 34391328ede..3a85ed48a7f 100644 --- a/usr.sbin/nsd/zonec.c +++ b/usr.sbin/nsd/zonec.c @@ -103,12 +103,12 @@ zparser_conv_hex(region_type *region, const char *hex, size_t len) while (*hex) { *t = 0; for (i = 16; i >= 1; i -= 15) { - if (isxdigit((int)*hex)) { + if (isxdigit((unsigned char)*hex)) { *t += hexdigit_to_int(*hex) * i; } else { zc_error_prev_line( "illegal hex character '%c'", - (int) *hex); + (int)(unsigned char) *hex); return NULL; } ++hex; @@ -144,12 +144,12 @@ zparser_conv_hex_length(region_type *region, const char *hex, size_t len) while (*hex) { *t = 0; for (i = 16; i >= 1; i -= 15) { - if (isxdigit((int)*hex)) { + if (isxdigit((unsigned char)*hex)) { *t += hexdigit_to_int(*hex) * i; } else { zc_error_prev_line( "illegal hex character '%c'", - (int) *hex); + (int)(unsigned char) *hex); return NULL; } ++hex; @@ -415,7 +415,7 @@ zparser_conv_ilnp64(region_type *region, const char *text) } else { /* Our grammar is stricter than the one accepted by * strtol. */ - c = (int) *ch; + c = (unsigned char) *ch; if (!isxdigit(c)) { zc_error_prev_line("ilnp64: invalid " "(non-hexadecimal) character %c", c); @@ -510,7 +510,7 @@ zparser_conv_eui(region_type *region, const char *text, size_t len) nnum = len/8; num = 1; for (ch = text; *ch != '\0'; ch++) { - int c = (int) *ch; + int c = (unsigned char) *ch; if (*ch == '-') { num++; } else if (!isxdigit(c)) { @@ -590,7 +590,7 @@ zparser_conv_tag(region_type *region, const char *text, size_t len) return NULL; } for (ptr = text; *ptr; ptr++) { - if (!isdigit(*ptr) && !islower(*ptr)) { + if (!isdigit((unsigned char)*ptr) && !islower((unsigned char)*ptr)) { zc_error_prev_line("invalid tag %s: contains invalid char %c", text, *ptr); return NULL; @@ -786,14 +786,14 @@ precsize_aton (char *cp, char **endptr) int exponent; int mantissa; - while (isdigit((int)*cp)) + while (isdigit((unsigned char)*cp)) mval = mval * 10 + hexdigit_to_int(*cp++); if (*cp == '.') { /* centimeters */ cp++; - if (isdigit((int)*cp)) { + if (isdigit((unsigned char)*cp)) { cmval = hexdigit_to_int(*cp++) * 10; - if (isdigit((int)*cp)) { + if (isdigit((unsigned char)*cp)) { cmval += hexdigit_to_int(*cp++); } } @@ -858,17 +858,17 @@ zparser_conv_loc(region_type *region, char *str) if (!parse_int(str, &str, °, "degrees", 0, 180)) return NULL; - if (!isspace((int)*str)) { + if (!isspace((unsigned char)*str)) { zc_error_prev_line("space expected after degrees"); return NULL; } ++str; /* Minutes? */ - if (isdigit((int)*str)) { + if (isdigit((unsigned char)*str)) { if (!parse_int(str, &str, &min, "minutes", 0, 60)) return NULL; - if (!isspace((int)*str)) { + if (!isspace((unsigned char)*str)) { zc_error_prev_line("space expected after minutes"); return NULL; } @@ -876,7 +876,7 @@ zparser_conv_loc(region_type *region, char *str) } /* Seconds? */ - if (isdigit((int)*str)) { + if (isdigit((unsigned char)*str)) { start = str; if (!parse_int(str, &str, &i, "seconds", 0, 60)) { return NULL; @@ -886,7 +886,7 @@ zparser_conv_loc(region_type *region, char *str) return NULL; } - if (!isspace((int)*str)) { + if (!isspace((unsigned char)*str)) { zc_error_prev_line("space expected after seconds"); return NULL; } @@ -929,7 +929,7 @@ zparser_conv_loc(region_type *region, char *str) if (lat != 0 && lon != 0) break; - if (!isspace((int)*str)) { + if (!isspace((unsigned char)*str)) { zc_error_prev_line("space expected after latitude/longitude"); return NULL; } @@ -942,7 +942,7 @@ zparser_conv_loc(region_type *region, char *str) return NULL; } - if (!isspace((int)*str)) { + if (!isspace((unsigned char)*str)) { zc_error_prev_line("space expected before altitude"); return NULL; } @@ -966,7 +966,7 @@ zparser_conv_loc(region_type *region, char *str) if (!parse_int(str + 1, &str, &i, "altitude fraction", 0, 99)) { return NULL; } - if (!isspace((int)*str) && *str != '\0' && *str != 'm') { + if (!isspace((unsigned char)*str) && *str != '\0' && *str != 'm') { zc_error_prev_line("altitude fraction must be a number"); return NULL; } @@ -975,7 +975,7 @@ zparser_conv_loc(region_type *region, char *str) zc_error_prev_line("altitude must be expressed in meters"); return NULL; } - if (!isspace((int)*str) && *str != '\0') + if (!isspace((unsigned char)*str) && *str != '\0') ++str; if (sscanf(start, "%lf", &d) != 1) { @@ -984,16 +984,16 @@ zparser_conv_loc(region_type *region, char *str) alt = (uint32_t) (10000000.0 + d * 100 + 0.5); - if (!isspace((int)*str) && *str != '\0') { + if (!isspace((unsigned char)*str) && *str != '\0') { zc_error_prev_line("unexpected character after altitude"); return NULL; } /* Now parse size, horizontal precision and vertical precision if any */ - for(i = 1; isspace((int)*str) && i <= 3; i++) { + for(i = 1; isspace((unsigned char)*str) && i <= 3; i++) { vszhpvp[i] = precsize_aton(str + 1, &str); - if (!isspace((int)*str) && *str != '\0') { + if (!isspace((unsigned char)*str) && *str != '\0') { zc_error_prev_line("invalid size or precision"); return NULL; } -- 2.20.1