summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJérémie Courrèges-Anglas <jca@wxcvbn.org>2013-11-22 00:10:46 +0100
committerJérémie Courrèges-Anglas <jca@wxcvbn.org>2013-11-22 00:10:46 +0100
commit5bc22db14b6ffd4cb39722a415d4cd176bb7fc0d (patch)
treeffe438dcf5f52c8e1148e1da3ca6b9fa64d9dc32
parent407dc8b5e6a4db430381000256c87ba313bbed5e (diff)
downloadratpoison-5bc22db14b6ffd4cb39722a415d4cd176bb7fc0d.zip
Cast char arguments to to*/is* ctype calls to unsigned char
* those functions expect an int whose value is between -1 and 255. Cast to unsigned char so that sign extension when promoting to int doesn't bite us.
-rw-r--r--src/actions.c18
-rw-r--r--src/editor.c16
-rw-r--r--src/history.c6
-rw-r--r--src/main.c11
4 files changed, 30 insertions, 21 deletions
diff --git a/src/actions.c b/src/actions.c
index 1ded570..17370be 100644
--- a/src/actions.c
+++ b/src/actions.c
@@ -19,7 +19,7 @@
*/
#include <unistd.h>
-#include <ctype.h> /* for isspace */
+#include <ctype.h>
#include <sys/wait.h>
#include <X11/keysym.h>
#include <string.h>
@@ -2311,7 +2311,10 @@ parse_args (char *str, struct list_head *list, int nargs, int raw)
{
struct sbuf *s = sbuf_new(0);
if (!raw)
- while (*i && isspace (*i)) i++;
+ {
+ while (*i && isspace ((unsigned char)*i))
+ i++;
+ }
if (*i)
{
sbuf_concat(s, i);
@@ -2324,7 +2327,8 @@ parse_args (char *str, struct list_head *list, int nargs, int raw)
/* Should we eat the whitespace? */
if (gobble)
{
- while (*i && isspace (*i)) i++;
+ while (*i && isspace ((unsigned char)*i))
+ i++;
gobble = 0;
}
@@ -2364,7 +2368,7 @@ parse_args (char *str, struct list_head *list, int nargs, int raw)
break;
}
}
- else if (isspace (*i) && !in_str)
+ else if (isspace ((unsigned char)*i) && !in_str)
{
/* End the current arg, and start a new one. */
struct sbuf *s = sbuf_new(0);
@@ -2468,10 +2472,12 @@ command (int interactive, char *data)
cmd = input;
/* skip beginning whitespace. */
- while (*cmd && isspace (*cmd)) cmd++;
+ while (*cmd && isspace ((unsigned char)*cmd))
+ cmd++;
rest = cmd;
/* skip til we get to whitespace */
- while (*rest && !isspace (*rest)) rest++;
+ while (*rest && !isspace ((unsigned char)*rest))
+ rest++;
/* mark that spot as the end of the command and make rest point to
the rest of the string. */
if (*rest)
diff --git a/src/editor.c b/src/editor.c
index 6c17754..3dabe89 100644
--- a/src/editor.c
+++ b/src/editor.c
@@ -192,11 +192,11 @@ editor_forward_word (rp_input_line *line)
return EDIT_NO_OP;
while (line->position < line->length
- && !isalnum (line->buffer[line->position]))
+ && !isalnum ((unsigned char)line->buffer[line->position]))
line->position++;
while (line->position < line->length
- && (isalnum (line->buffer[line->position])
+ && (isalnum ((unsigned char)line->buffer[line->position])
|| RP_IS_UTF8_CHAR (line->buffer[line->position])))
line->position++;
@@ -209,11 +209,11 @@ editor_backward_word (rp_input_line *line)
if (line->position == 0)
return EDIT_NO_OP;
- while (line->position > 0 && !isalnum (line->buffer[line->position]))
+ while (line->position > 0 && !isalnum ((unsigned char)line->buffer[line->position]))
line->position--;
while (line->position > 0
- && (isalnum (line->buffer[line->position])
+ && (isalnum ((unsigned char)line->buffer[line->position])
|| RP_IS_UTF8_CHAR (line->buffer[line->position])))
line->position--;
@@ -301,11 +301,11 @@ editor_kill_word (rp_input_line *line)
return EDIT_NO_OP;
while (line->position + diff < line->length &&
- !isalnum (line->buffer[line->position + diff]))
+ !isalnum ((unsigned char)line->buffer[line->position + diff]))
diff++;
while (line->position + diff < line->length
- && (isalnum (line->buffer[line->position + diff])
+ && (isalnum ((unsigned char)line->buffer[line->position + diff])
|| RP_IS_UTF8_CHAR (line->buffer[line->position + diff])))
diff++;
@@ -330,11 +330,11 @@ editor_backward_kill_word (rp_input_line *line)
return EDIT_NO_OP;
while (line->position - diff > 0 &&
- !isalnum (line->buffer[line->position - diff]))
+ !isalnum ((unsigned char)line->buffer[line->position - diff]))
diff++;
while (line->position - diff > 0
- && (isalnum (line->buffer[line->position - diff])
+ && (isalnum ((unsigned char)line->buffer[line->position - diff])
|| RP_IS_UTF8_CHAR (line->buffer[line->position - diff])))
diff++;
diff --git a/src/history.c b/src/history.c
index b48feb9..7a6cf15 100644
--- a/src/history.c
+++ b/src/history.c
@@ -54,9 +54,9 @@ extract_shell_part (const char *p)
if (strncmp(p, "exec", 4) &&
strncmp(p, "verbexec", 8))
return NULL;
- while( *p && !isspace(*p) )
+ while (*p && !isspace ((unsigned char)*p))
p++;
- while( *p && isspace(*p) )
+ while (*p && isspace ((unsigned char)*p))
p++;
if (*p)
return p;
@@ -114,7 +114,7 @@ history_add_upto (int history_id, const char *item, size_t max)
struct history *h = histories + history_id;
struct history_item *i;
- if (item == NULL || *item == '\0' || isspace(*item))
+ if (item == NULL || *item == '\0' || isspace((unsigned char)*item))
return;
list_last (i, &histories[history_id].head, node);
diff --git a/src/main.c b/src/main.c
index 3855bac..bedba19 100644
--- a/src/main.c
+++ b/src/main.c
@@ -180,7 +180,8 @@ strtok_ws (char *s)
}
/* skip to first non-whitespace char. */
- while (*last && isspace (*last)) last++;
+ while (*last && isspace ((unsigned char)*last))
+ last++;
/* If we reached the end of the string here then there is no more
data. */
@@ -189,7 +190,8 @@ strtok_ws (char *s)
/* Now skip to the end of the data. */
nonws = last;
- while (*last && !isspace (*last)) last++;
+ while (*last && !isspace ((unsigned char)*last))
+ last++;
if (*last)
{
*last = '\0';
@@ -204,8 +206,9 @@ str_comp (char *s1, char *s2, int len)
{
int i;
- for (i=0; i<len; i++)
- if (toupper (s1[i]) != toupper (s2[i])) return 0;
+ for (i = 0; i < len; i++)
+ if (toupper ((unsigned char)s1[i]) != toupper ((unsigned char)s2[i]))
+ return 0;
return 1;
}