Fix NetBSD ctype warnings.
authorDavid Woodhouse <David.Woodhouse@intel.com>
Fri, 4 Nov 2011 18:24:34 +0000 (18:24 +0000)
committerDavid Woodhouse <David.Woodhouse@intel.com>
Fri, 4 Nov 2011 21:34:36 +0000 (21:34 +0000)
We have to cast to int via unsigned char. Ick.

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
auth.c
ssl.c
tun.c

diff --git a/auth.c b/auth.c
index aa40249..c0549b8 100644 (file)
--- a/auth.c
+++ b/auth.c
@@ -51,7 +51,7 @@ static int append_opt(char *body, int bodylen, char *opt, char *name)
        }
 
        while (*opt) {
-               if (isalnum(*opt)) {
+               if (isalnum((int)(unsigned char)*opt)) {
                        if (len >= bodylen - 1)
                                return -ENOSPC;
                        body[len++] = *opt;
@@ -69,7 +69,7 @@ static int append_opt(char *body, int bodylen, char *opt, char *name)
        body[len++] = '=';
 
        while (name && *name) {
-               if (isalnum(*name)) {
+               if (isalnum((int)(unsigned char)*name)) {
                        if (len >= bodylen - 1)
                                return -ENOSPC;
                        body[len++] = *name;
diff --git a/ssl.c b/ssl.c
index d826131..70e21e9 100644 (file)
--- a/ssl.c
+++ b/ssl.c
@@ -479,7 +479,14 @@ static int match_hostname_elem(const char *hostname, int helem_len,
                return -1;
        }
 
-       if (toupper(hostname[0]) == toupper(match[0]))
+       /* From the NetBSD (5.1) man page for ctype(3):
+           Values of type char or signed char must first be cast to unsigned char,
+          to ensure that the values are within the correct range.  The result
+          should then be cast to int to avoid warnings from some compilers.
+          We do indeed get warning "array subscript has type 'char'" without
+          the casts. Ick. */
+       if (toupper((int)(unsigned char)hostname[0]) ==
+           toupper((int)(unsigned char)match[0]))
                return match_hostname_elem(hostname + 1, helem_len - 1,
                                           match + 1, melem_len - 1);
 
diff --git a/tun.c b/tun.c
index 3fc2e70..eb56657 100644 (file)
--- a/tun.c
+++ b/tun.c
@@ -258,7 +258,8 @@ static void set_banner(struct openconnect_info *vpninfo)
        q = banner;
        
        while (*p) {
-               if (*p == '%' && isxdigit(p[1]) && isxdigit(p[2])) {
+               if (*p == '%' && isxdigit((int)(unsigned char)p[1]) &&
+                   isxdigit((int)(unsigned char)p[2])) {
                        *(q++) = unhex(p + 1);
                        p += 3;
                } else