Use proper casts for ctype functions. This is already fixed in nsd
authormillert <millert@openbsd.org>
Mon, 12 Jan 2015 14:36:48 +0000 (14:36 +0000)
committermillert <millert@openbsd.org>
Mon, 12 Jan 2015 14:36:48 +0000 (14:36 +0000)
trunk.  OK doug@

usr.sbin/nsd/compat/b64_pton.c
usr.sbin/nsd/compat/inet_aton.c
usr.sbin/nsd/compat/strptime.c
usr.sbin/nsd/dns.c
usr.sbin/nsd/nsd.c
usr.sbin/nsd/rdata.c
usr.sbin/nsd/remote.c
usr.sbin/nsd/tsig.c
usr.sbin/nsd/util.c
usr.sbin/nsd/zlexer.lex
usr.sbin/nsd/zonec.c

index 0850604..0e4aafc 100644 (file)
@@ -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
index 7eb8e62..430f9b0 100644 (file)
@@ -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
index 4ec96c1..e6eb375 100644 (file)
@@ -91,7 +91,7 @@ str2int(const char **buf, int max)
 {
        int ret=0, count=0;
 
-       while (*buf[0] != '\0' && isdigit(*buf[0]) && count<max) {
+       while (*buf[0] != '\0' && isdigit((unsigned char)*buf[0]) && count<max) {
                ret = ret*10 + (*buf[0] - '0');
                (*buf)++;
                count++;
@@ -111,7 +111,7 @@ nsd_strptime(const char *s, const char *format, struct tm *tm)
        int c, alt_format, ret;
        int split_year = 0;
 
-       while ((c = *format) != '\0') {
+       while ((c = (unsigned char)*format) != '\0') {
                alt_format = 0;
 
                /* whitespace, literal or format */
@@ -119,7 +119,7 @@ nsd_strptime(const char *s, const char *format, struct tm *tm)
                        /** whitespace matches zero or more whitespace characters in the
                          * input string.
                         **/
-                       while (isspace(*s))
+                       while (isspace((unsigned char)*s))
                                s++;
                }
                else if (c == '%') { /* format */
@@ -225,7 +225,7 @@ nsd_strptime(const char *s, const char *format, struct tm *tm)
                                        break;
                                case 'n': /* arbitrary whitespace */
                                case 't':
-                                       while (isspace(*s))
+                                       while (isspace((unsigned char)*s))
                                                s++;
                                        break;
                                case 'p': /* am pm */
index 5d80f8a..b10a538 100644 (file)
@@ -891,7 +891,7 @@ rrtype_from_string(const char *name)
        if (strncasecmp(name, "TYPE", 4) != 0)
                return 0;
 
-       if (!isdigit((int)name[4]))
+       if (!isdigit((unsigned char)name[4]))
                return 0;
 
        /* The rest from the string must be a number.  */
@@ -936,7 +936,7 @@ rrclass_from_string(const char *name)
        if (strncasecmp(name, "CLASS", 5) != 0)
                return 0;
 
-       if (!isdigit((int)name[5]))
+       if (!isdigit((unsigned char)name[5]))
                return 0;
 
        /* The rest from the string must be a number.  */
index b8cfd3e..dc37b31 100644 (file)
@@ -829,11 +829,11 @@ main(int argc, char *argv[])
 #ifdef HAVE_GETPWNAM
        /* Parse the username into uid and gid */
        if (*nsd.username) {
-               if (isdigit((int)*nsd.username)) {
+               if (isdigit((unsigned char)*nsd.username)) {
                        char *t;
                        nsd.uid = strtol(nsd.username, &t, 10);
                        if (*t != 0) {
-                               if (*t != '.' || !isdigit((int)*++t)) {
+                               if (*t != '.' || !isdigit((unsigned char)*++t)) {
                                        error("-u user or -u uid or -u uid.gid");
                                }
                                nsd.gid = strtol(t, &t, 10);
index 9d01c6c..ec5d6ff 100644 (file)
@@ -98,9 +98,9 @@ rdata_dns_name_to_string(buffer_type *output, rdata_atom_type rdata,
 
                        if (ch=='.' || ch==';' || ch=='(' || ch==')' || ch=='\\') {
                                buffer_printf(output, "\\%c", (char) ch);
-                       } else if (!isgraph((int)(unsigned char) ch)) {
+                       } else if (!isgraph((unsigned char) ch)) {
                                buffer_printf(output, "\\%03u", (unsigned int) ch);
-                       } else if (isprint((int)(unsigned char) ch)) {
+                       } else if (isprint((unsigned char) ch)) {
                                buffer_printf(output, "%c", (char) ch);
                        } else {
                                buffer_printf(output, "\\%03u", (unsigned int) ch);
@@ -127,7 +127,7 @@ rdata_text_to_string(buffer_type *output, rdata_atom_type rdata,
        buffer_printf(output, "\"");
        for (i = 1; i <= length; ++i) {
                char ch = (char) data[i];
-               if (isprint((int)(unsigned char)ch)) {
+               if (isprint((unsigned char)ch)) {
                        if (ch == '"' || ch == '\\') {
                                buffer_printf(output, "\\");
                        }
@@ -153,7 +153,7 @@ rdata_texts_to_string(buffer_type *output, rdata_atom_type rdata,
                buffer_printf(output, "\"");
                for (i = 1; i <= data[pos]; ++i) {
                        char ch = (char) data[pos + i];
-                       if (isprint((int)(unsigned char)ch)) {
+                       if (isprint((unsigned char)ch)) {
                                if (ch == '"' || ch == '\\') {
                                        buffer_printf(output, "\\");
                                }
@@ -179,7 +179,7 @@ rdata_long_text_to_string(buffer_type *output, rdata_atom_type rdata,
        buffer_printf(output, "\"");
        for (i = 0; i < length; ++i) {
                char ch = (char) data[i];
-               if (isprint((int)(unsigned char)ch)) {
+               if (isprint((unsigned char)ch)) {
                        if (ch == '"' || ch == '\\') {
                                buffer_printf(output, "\\");
                        }
@@ -201,7 +201,7 @@ rdata_tag_to_string(buffer_type *output, rdata_atom_type rdata,
        size_t i;
        for (i = 1; i <= length; ++i) {
                char ch = (char) data[i];
-               if (isdigit((int)ch) || islower((int)ch))
+               if (isdigit((unsigned char)ch) || islower((unsigned char)ch))
                        buffer_printf(output, "%c", ch);
                else    return 0;
        }
index 82b4999..18ca7a6 100644 (file)
@@ -731,7 +731,7 @@ static char*
 skipwhite(char* str)
 {
        /* EOS \0 is not a space */
-       while( isspace(*str) ) 
+       while( isspace((unsigned char)*str) ) 
                str++;
        return str;
 }
@@ -1036,7 +1036,7 @@ find_arg2(SSL* ssl, char* arg, char** arg2)
        if(as) {
                as[0]=0;
                *arg2 = as+1;
-               while(isspace(*as) && as > arg)
+               while(isspace((unsigned char)*as) && as > arg)
                        as--;
                as[0]=0;
                return 1;
index 1844e98..316f477 100644 (file)
@@ -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;
                }
index 7d93f54..7af07d0 100644 (file)
@@ -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';
 
index 56ad724..90a1df3 100644 (file)
@@ -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 +
index 3439132..3a85ed4 100644 (file)
@@ -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, &deg, "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;
                }