From 0fcb95163b43ee1cdd0935ef42a297377297b3b9 Mon Sep 17 00:00:00 2001
From: Hans-Bernhard Broeker <HBBroeker@T-Online.de>
Date: Sun, 12 Feb 2017 18:58:48 +0100
Subject: [PATCH] Make sure calls to <ctype.h> functions/macros work even if
 platform's "char" is signed.

---
 src/browser.c |  2 +-
 src/chars.c   |  6 +++---
 src/global.c  |  2 +-
 src/rcfile.c  | 20 ++++++++++----------
 4 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/src/browser.c b/src/browser.c
index 5f84060..8bc5536 100644
--- a/src/browser.c
+++ b/src/browser.c
@@ -54,7 +54,7 @@ char *do_browser(char *path)
 	/* The number of the selected file before the current selected file. */
     functionptrtype func;
 	/* The function of the key the user typed in. */
-    DIR *dir;
+    DIR *dir = NULL;
 	/* The directory whose contents we are showing. */
 
     /* Don't show a cursor in the file list. */
diff --git a/src/chars.c b/src/chars.c
index a683177..8d55eb5 100644
--- a/src/chars.c
+++ b/src/chars.c
@@ -472,11 +472,11 @@ int nstrncasecmp(const char *s1, const char *s2, size_t n)
 	return 0;
 
     for (; *s1 != '\0' && *s2 != '\0' && n > 0; s1++, s2++, n--) {
-	if (tolower(*s1) != tolower(*s2))
+	if (tolower((unsigned char)*s1) != tolower((unsigned char)*s2))
 	    break;
     }
 
-    return (n > 0) ? tolower(*s1) - tolower(*s2) : 0;
+    return (n > 0) ? tolower((unsigned char)*s1) - tolower((unsigned char)*s2) : 0;
 }
 #endif
 
@@ -815,7 +815,7 @@ char *mbrevstrpbrk(const char *s, const char *accept, const char
 bool has_blank_chars(const char *s)
 {
     for (; *s != '\0'; s++) {
-	if (isblank(*s))
+	if (isblank((unsigned char)*s))
 	    return TRUE;
     }
 
diff --git a/src/global.c b/src/global.c
index 690dfc6..7be5b13 100644
--- a/src/global.c
+++ b/src/global.c
@@ -431,7 +431,7 @@ void assign_keyinfo(sc *s, const char *keystring, const int keycode)
 	if (strcasecmp(keystring, "M-Space") == 0)
 	    s->keycode = (int)' ';
 	else
-	    s->keycode = tolower((int)keystring[2]);
+	    s->keycode = tolower((unsigned char)keystring[2]);
     } else if (keystring[0] == 'F')
 	s->keycode = KEY_F0 + atoi(&keystring[1]);
     else if (!strcasecmp(keystring, "Ins"))
diff --git a/src/rcfile.c b/src/rcfile.c
index 372482c..414d8f2 100644
--- a/src/rcfile.c
+++ b/src/rcfile.c
@@ -169,7 +169,7 @@ void rcfile_error(const char *msg, ...)
  * returned pointer will point to '\0' if we hit the end of the line. */
 char *parse_next_word(char *ptr)
 {
-    while (!isblank(*ptr) && *ptr != '\0')
+    while (!isblank((unsigned char)*ptr) && *ptr != '\0')
 	ptr++;
 
     if (*ptr == '\0')
@@ -178,7 +178,7 @@ char *parse_next_word(char *ptr)
     /* Null-terminate and advance ptr. */
     *ptr++ = '\0';
 
-    while (isblank(*ptr))
+    while (isblank((unsigned char)*ptr))
 	ptr++;
 
     return ptr;
@@ -217,7 +217,7 @@ char *parse_argument(char *ptr)
 	ptr = last_quote + 1;
     }
     if (ptr != NULL)
-	while (isblank(*ptr))
+	while (isblank((unsigned char)*ptr))
 	    ptr++;
     return ptr;
 }
@@ -232,7 +232,7 @@ char *parse_next_regex(char *ptr)
     /* Continue until the end of line, or until a " followed by a
      * blank character or the end of line. */
     while (*ptr != '\0' && (*ptr != '"' ||
-		(*(ptr + 1) != '\0' && !isblank(*(ptr + 1)))))
+		(*(ptr + 1) != '\0' && !isblank((unsigned char)ptr[1]))))
 	ptr++;
 
     assert(*ptr == '"' || *ptr == '\0');
@@ -246,7 +246,7 @@ char *parse_next_regex(char *ptr)
     /* Null-terminate and advance ptr. */
     *ptr++ = '\0';
 
-    while (isblank(*ptr))
+    while (isblank((unsigned char)*ptr))
 	ptr++;
 
     return ptr;
@@ -389,11 +389,11 @@ void parse_binding(char *ptr, bool dobind)
     }
 
     /* Uppercase only the first two or three characters of the key name. */
-    keycopy[0] = toupper(keycopy[0]);
-    keycopy[1] = toupper(keycopy[1]);
+    keycopy[0] = toupper((unsigned char)keycopy[0]);
+    keycopy[1] = toupper((unsigned char)keycopy[1]);
     if (keycopy[0] == 'M' && keycopy[1] == '-') {
 	if (strlen(keycopy) > 2)
-	    keycopy[2] = toupper(keycopy[2]);
+	    keycopy[2] = toupper((unsigned char)keycopy[2]);
 	else {
 	    rcfile_error(N_("Key name is too short"));
 	    goto free_copy;
@@ -403,7 +403,7 @@ void parse_binding(char *ptr, bool dobind)
     /* Allow the codes for Insert and Delete to be rebound, but apart
      * from those two only Control, Meta and Function sequences. */
     if (!strcasecmp(keycopy, "Ins") || !strcasecmp(keycopy, "Del"))
-	keycopy[1] = tolower(keycopy[1]);
+	keycopy[1] = tolower((unsigned char)keycopy[1]);
     else if (keycopy[0] != '^' && keycopy[0] != 'M' && keycopy[0] != 'F') {
 	rcfile_error(N_("Key name must begin with \"^\", \"M\", or \"F\""));
 	goto free_copy;
@@ -959,7 +959,7 @@ void parse_rcfile(FILE *rcstream, bool syntax_only)
 
 	lineno++;
 	ptr = buf;
-	while (isblank(*ptr))
+	while (isblank((unsigned char)*ptr))
 	    ptr++;
 
 	/* If we have a blank line or a comment, skip to the next
-- 
2.8.3

