From: Matthias Braun Date: Thu, 20 Oct 2011 12:26:36 +0000 (+0200) Subject: cast ctype functions input to unsigned char X-Git-Url: http://nsz.repo.hu/git/?a=commitdiff_plain;h=573f2284df8276913dfcf63c795cc6cfbe15462a;p=libfirm cast ctype functions input to unsigned char 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) --- diff --git a/ir/debug/debugger.c b/ir/debug/debugger.c index b2cafc0f1..d5a753eaa 100644 --- a/ir/debug/debugger.c +++ b/ir/debug/debugger.c @@ -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(); diff --git a/ir/ir/irargs.c b/ir/ir/irargs.c index 5af12d18f..14f1ea0c5 100644 --- a/ir/ir/irargs.c +++ b/ir/ir/irargs.c @@ -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; } diff --git a/ir/libcore/lc_opts.c b/ir/libcore/lc_opts.c index d68318fd2..3c33724b0 100644 --- a/ir/libcore/lc_opts.c +++ b/ir/libcore/lc_opts.c @@ -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; } diff --git a/ir/libcore/lc_printf.c b/ir/libcore/lc_printf.c index 471f751a1..2e6cedf40 100644 --- a/ir/libcore/lc_printf.c +++ b/ir/libcore/lc_printf.c @@ -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; }