Commit 573f2284 authored by Matthias Braun's avatar Matthias Braun
Browse files

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)
parent 158da8a4
......@@ -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();
......
......@@ -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;
}
......
......@@ -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;
}
......
......@@ -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;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment