cast ctype functions input to unsigned char
authorMatthias Braun <matze@braunis.de>
Thu, 20 Oct 2011 12:26:36 +0000 (14:26 +0200)
committerMatthias Braun <matze@braunis.de>
Thu, 20 Oct 2011 12:27:26 +0000 (14:27 +0200)
From the manpage: If c is not an unsigned char value, or EOF, the
behavior of these functions is undefined.
(So putting char into them directly is wrong)

ir/debug/debugger.c
ir/ir/irargs.c
ir/libcore/lc_opts.c
ir/libcore/lc_printf.c

index b2cafc0..d5a753e 100644 (file)
@@ -974,10 +974,10 @@ static unsigned get_token(void)
        /* skip white space */
        do {
                c = next_char();
-       } while (c != '\0' && isspace(c));
+       } while (c != '\0' && isspace((unsigned char)c));
 
        lexer.tok_start = lexer.curr_pos - 1;
-       if (c == '.' || isalpha(c)) {
+       if (c == '.' || isalpha((unsigned char)c)) {
                /* command begins here */
                int         len = 0;
                const char* tok_start;
@@ -985,7 +985,7 @@ static unsigned get_token(void)
                do {
                        c = next_char();
                        ++len;
-               } while (isgraph(c));
+               } while (isgraph((unsigned char)c));
                unput();
 
                tok_start = lexer.tok_start;
@@ -1002,7 +1002,7 @@ static unsigned get_token(void)
                lexer.s   = lexer.tok_start;
                lexer.len = lexer.curr_pos - lexer.s;
                return tok_identifier;
-       } else if (isdigit(c) || c == '-') {
+       } else if (isdigit((unsigned char)c) || c == '-') {
                unsigned number = 0;
                unsigned sign   = 0;
 
@@ -1019,12 +1019,12 @@ static unsigned get_token(void)
                                for (;;) {
                                        c = next_char();
 
-                                       if (! isxdigit(c))
+                                       if (! isxdigit((unsigned char)c))
                                                break;
-                                       if (isdigit(c))
+                                       if (isdigit((unsigned char)c))
                                                number = (number << 4) | (c - '0');
                                        else
-                                               number = (number << 4) | (toupper(c) - 'A' + 10);
+                                               number = (number << 4) | (toupper((unsigned char)c) - 'A' + 10);
                                }
                                unput();
                                lexer.number = number;
@@ -1032,7 +1032,7 @@ static unsigned get_token(void)
                        }
                }
                for (;;) {
-                       if (! isdigit(c))
+                       if (! isdigit((unsigned char)c))
                                break;
                        number = number * 10 + (c - '0');
                        c = next_char();
index 5af12d1..14f1ea0 100644 (file)
@@ -140,7 +140,7 @@ static int firm_emit(lc_appendable_t *app,
        case k_entity: {
                ir_entity *entity = (ir_entity*)X;
                snprintf(buf, sizeof(buf), "%s%s", A("ent"),
-                       isupper(occ->conversion) ? get_entity_ld_name_ex(entity): get_entity_name(entity));
+                       isupper((unsigned char)occ->conversion) ? get_entity_ld_name_ex(entity): get_entity_name(entity));
                snprintf(add, sizeof(add), "[%ld]", get_entity_nr(entity));
                break;
        }
index d68318f..3c33724 100644 (file)
@@ -335,7 +335,7 @@ static char *strtolower(char *buf, size_t n, const char *str)
 {
        unsigned i;
        for (i = 0; i < n; ++i)
-               buf[i] = tolower(str[i]);
+               buf[i] = tolower((unsigned char)str[i]);
        return buf;
 }
 
index 471f751..2e6cedf 100644 (file)
@@ -104,11 +104,11 @@ int lc_arg_register(lc_arg_env_t *env, const char *name, char letter, const lc_a
        arg.letter = letter;
        arg.handler = handler;
 
-       if (isupper(letter)) {
+       if (isupper((unsigned char)letter)) {
                map = env->upper;
                base = 'A';
        }
-       else if (islower(letter)) {
+       else if (islower((unsigned char)letter)) {
                map = env->lower;
                base = 'a';
        }
@@ -462,12 +462,12 @@ int lc_evpprintf(const lc_arg_env_t *env, lc_appendable_t *app, const char *fmt,
                                        const char *mod = s;
 
                                        /* Read, as long there are letters */
-                                       while (isalpha(ch) && !arg) {
+                                       while (isalpha((unsigned char)ch) && !arg) {
                                                int base = 'a';
                                                lc_arg_t * const *map = env->lower;
 
                                                /* If uppercase, select the uppercase map from the environment */
-                                               if (isupper(ch)) {
+                                               if (isupper((unsigned char)ch)) {
                                                        base = 'A';
                                                        map = env->upper;
                                                }