BUILD: tree-wide: cast arguments to tolower/toupper to unsigned char
NetBSD apparently uses macros for tolower/toupper and complains about
the use of char for array subscripts. Let's properly cast all of them
to unsigned char where they are used.
This is needed to fix issue #729.
diff --git a/src/dns.c b/src/dns.c
index 6f951ab..49b1c49 100644
--- a/src/dns.c
+++ b/src/dns.c
@@ -79,7 +79,7 @@
int i;
for (i = 0; i < len; i++)
- if (tolower(name1[i]) != tolower(name2[i]))
+ if (tolower((unsigned char)name1[i]) != tolower((unsigned char)name2[i]))
return -1;
return 0;
}
diff --git a/src/h1.c b/src/h1.c
index 368eb14..bb8acfb 100644
--- a/src/h1.c
+++ b/src/h1.c
@@ -662,7 +662,7 @@
if (!skip_update) {
/* turn it to lower case if needed */
if (isupper((unsigned char)*ptr) && h1m->flags & H1_MF_TOLOWER)
- *ptr = tolower(*ptr);
+ *ptr = tolower((unsigned char)*ptr);
}
EAT_AND_JUMP_OR_RETURN(ptr, end, http_msg_hdr_name, http_msg_ood, state, H1_MSG_HDR_NAME);
}
diff --git a/src/pattern.c b/src/pattern.c
index 416e809..a404ac3 100644
--- a/src/pattern.c
+++ b/src/pattern.c
@@ -782,7 +782,7 @@
icase = expr->mflags & PAT_MF_IGNORE_CASE;
if (icase) {
for (c = smp->data.u.str.area; c <= end; c++) {
- if (tolower(*c) != tolower(*pattern->ptr.str))
+ if (tolower((unsigned char)*c) != tolower((unsigned char)*pattern->ptr.str))
continue;
if (strncasecmp(pattern->ptr.str, c, pattern->len) == 0) {
ret = pattern;
@@ -847,7 +847,7 @@
continue;
if (icase) {
- if ((tolower(*c) == tolower(*ps)) &&
+ if ((tolower((unsigned char)*c) == tolower((unsigned char)*ps)) &&
(strncasecmp(ps, c, pl) == 0) &&
(c == end || is_delimiter(c[pl], delimiters)))
return PAT_MATCH;
diff --git a/src/regex.c b/src/regex.c
index e23e311..503be03 100644
--- a/src/regex.c
+++ b/src/regex.c
@@ -57,12 +57,12 @@
if (!*str)
return -1;
- hex1 = toupper(*str++) - '0';
+ hex1 = toupper((unsigned char)*str++) - '0';
if (!*str)
return -1;
- hex2 = toupper(*str++) - '0';
+ hex2 = toupper((unsigned char)*str++) - '0';
if (hex1 > 9) hex1 -= 'A' - '9' - 1;
if (hex2 > 9) hex2 -= 'A' - '9' - 1;
diff --git a/src/ssl_sock.c b/src/ssl_sock.c
index a32db1a..02967f6 100644
--- a/src/ssl_sock.c
+++ b/src/ssl_sock.c
@@ -2386,7 +2386,7 @@
for (i = 0; i < trash.size; i++) {
if (!servername[i])
break;
- trash.area[i] = tolower(servername[i]);
+ trash.area[i] = tolower((unsigned char)servername[i]);
if (!wildp && (trash.area[i] == '.'))
wildp = &trash.area[i];
}
@@ -2681,7 +2681,7 @@
int j, len;
len = strlen(name);
for (j = 0; j < len && j < trash.size; j++)
- trash.area[j] = tolower(name[j]);
+ trash.area[j] = tolower((unsigned char)name[j]);
if (j >= trash.size)
return -1;
trash.area[j] = 0;
@@ -2985,7 +2985,7 @@
for (i = 0; i < trash.size; i++) {
if (!str[i])
break;
- trash.area[i] = tolower(str[i]);
+ trash.area[i] = tolower((unsigned char)str[i]);
}
trash.area[i] = 0;
node = ebst_lookup(sni_keytypes, trash.area);
diff --git a/src/tools.c b/src/tools.c
index 39a4538..f4f96a6 100644
--- a/src/tools.c
+++ b/src/tools.c
@@ -3921,7 +3921,7 @@
return NULL;
for (tmp1 = 0, start = (char *)str1, pptr = (char *)str2, slen = len_str1, plen = len_str2; slen >= plen; start++, slen--) {
- while (toupper(*start) != toupper(*str2)) {
+ while (toupper((unsigned char)*start) != toupper((unsigned char)*str2)) {
start++;
slen--;
tmp1++;
@@ -3938,7 +3938,7 @@
pptr = (char *)str2;
tmp2 = 0;
- while (toupper(*sptr) == toupper(*pptr)) {
+ while (toupper((unsigned char)*sptr) == toupper((unsigned char)*pptr)) {
sptr++;
pptr++;
tmp2++;
@@ -4882,8 +4882,8 @@
*errptr = in;
goto leave;
}
- hex1 = toupper(in[2]) - '0';
- hex2 = toupper(in[3]) - '0';
+ hex1 = toupper((unsigned char)in[2]) - '0';
+ hex2 = toupper((unsigned char)in[3]) - '0';
if (hex1 > 9) hex1 -= 'A' - '9' - 1;
if (hex2 > 9) hex2 -= 'A' - '9' - 1;
tosend = (hex1 << 4) + hex2;