explicitly casting to unsigned char when using isalpha/digit/etc.

This commit is contained in:
Alex Shinn 2011-11-14 15:27:02 +09:00
parent 70eb98d0f8
commit 7dd811ad57
3 changed files with 11 additions and 11 deletions

View file

@ -16,11 +16,11 @@ extern "C" {
#if defined(_WIN32) || defined(__MINGW32__) #if defined(_WIN32) || defined(__MINGW32__)
#include <windows.h> #include <windows.h>
#define sexp_isalpha(x) ((isalpha)((int)(unsigned int)(x))) #define sexp_isalpha(x) ((isalpha)((int)(x)))
#define sexp_isxdigit(x) ((isxdigit)((int)(unsigned int)(x))) #define sexp_isxdigit(x) ((isxdigit)((int)(x)))
#define sexp_isdigit(x) ((isdigit)((int)(unsigned int)(x))) #define sexp_isdigit(x) ((isdigit)((int)(x)))
#define sexp_tolower(x) ((tolower)((int)(unsigned int)(x))) #define sexp_tolower(x) ((tolower)((int)(x)))
#define sexp_toupper(x) ((toupper)((int)(unsigned int)(x))) #define sexp_toupper(x) ((toupper)((int)(x)))
#else #else
#if SEXP_USE_DL #if SEXP_USE_DL
#include <dlfcn.h> #include <dlfcn.h>

4
main.c
View file

@ -336,10 +336,10 @@ void run_main (int argc, char **argv) {
arg = ((argv[i][2] == '\0') ? argv[++i] : argv[i]+2); arg = ((argv[i][2] == '\0') ? argv[++i] : argv[i]+2);
check_nonull_arg('h', arg); check_nonull_arg('h', arg);
heap_size = strtoul(arg, &arg, 0); heap_size = strtoul(arg, &arg, 0);
if (sexp_isalpha(*arg)) heap_size *= multiplier(*arg++); if (sexp_isalpha((unsigned char)*arg)) heap_size *= multiplier(*arg++);
if (*arg == '/') { if (*arg == '/') {
heap_max_size = strtoul(arg+1, &arg, 0); heap_max_size = strtoul(arg+1, &arg, 0);
if (sexp_isalpha(*arg)) heap_max_size *= multiplier(*arg++); if (sexp_isalpha((unsigned char)*arg)) heap_max_size *= multiplier(*arg++);
} }
break; break;
#if SEXP_USE_IMAGE_LOADING #if SEXP_USE_IMAGE_LOADING

8
sexp.c
View file

@ -2386,8 +2386,8 @@ sexp sexp_read_raw (sexp ctx, sexp in) {
if (sexp_string_length(res) == 1) { if (sexp_string_length(res) == 1) {
res = sexp_make_character(c1); res = sexp_make_character(c1);
} else if ((c1 == 'x' || c1 == 'X') && } else if ((c1 == 'x' || c1 == 'X') &&
sexp_isxdigit(str[1]) sexp_isxdigit((unsigned char)(str[1]))
&& sexp_isxdigit(str[2]) && str[3] == '\0') { && sexp_isxdigit((unsigned char)(str[2])) && str[3] == '\0') {
res = sexp_make_character(16 * digit_value(str[1]) res = sexp_make_character(16 * digit_value(str[1])
+ digit_value(str[2])); + digit_value(str[2]));
} else { } else {
@ -2564,12 +2564,12 @@ sexp sexp_string_to_number_op (sexp ctx, sexp self, sexp_sint_t n, sexp str, sex
if (((base=sexp_unbox_fixnum(b)) < 2) || (base > 36)) if (((base=sexp_unbox_fixnum(b)) < 2) || (base > 36))
return sexp_user_exception(ctx, self, "invalid numeric base", b); return sexp_user_exception(ctx, self, "invalid numeric base", b);
if (sexp_string_data(str)[0]=='\0' if (sexp_string_data(str)[0]=='\0'
|| (sexp_string_data(str)[1]=='\0' && !sexp_isdigit(sexp_string_data(str)[0]))) || (sexp_string_data(str)[1]=='\0' && !sexp_isdigit((unsigned char)(sexp_string_data(str)[0]))))
return SEXP_FALSE; return SEXP_FALSE;
sexp_gc_preserve1(ctx, in); sexp_gc_preserve1(ctx, in);
in = sexp_make_input_string_port(ctx, str); in = sexp_make_input_string_port(ctx, str);
if (sexp_string_data(str)[0] == '+') { if (sexp_string_data(str)[0] == '+') {
if (sexp_isdigit(sexp_string_data(str)[1]) if (sexp_isdigit((unsigned char)(sexp_string_data(str)[1]))
|| sexp_string_data(str)[1] == '.' || sexp_string_data(str)[1] == '#') || sexp_string_data(str)[1] == '.' || sexp_string_data(str)[1] == '#')
sexp_read_char(ctx, in); sexp_read_char(ctx, in);
} }