diff --git a/hawk/lib/hawk-chr.h b/hawk/lib/hawk-chr.h index 545e2844..eab266b6 100644 --- a/hawk/lib/hawk-chr.h +++ b/hawk/lib/hawk-chr.h @@ -91,6 +91,11 @@ typedef enum hawk_ooch_prop_t hawk_bch_prop_t; ((c) >= 'A' && (c) <= 'F')? ((c) - 'A' + 10): \ ((c) >= 'a' && (c) <= 'f')? ((c) - 'a' + 10): -1) +#define HAWK_ZDIGIT_TO_NUM(c,base) \ + (((c) >= '0' && (c) <= '9')? ((c) - '0'): \ + ((c) >= 'A' && (c) <= 'Z')? ((c) - 'A' + 10): \ + ((c) >= 'a' && (c) <= 'z')? ((c) - 'a' + 10): base) + #if defined(__cplusplus) extern "C" { #endif diff --git a/hawk/lib/utl-str.c b/hawk/lib/utl-str.c index 59189049..3b32f58f 100644 --- a/hawk/lib/utl-str.c +++ b/hawk/lib/utl-str.c @@ -2615,21 +2615,19 @@ hawk_int_t hawk_uchars_to_int (const hawk_uch_t* str, hawk_oow_t len, int option } else if (rem >= 2 && base == 16) { - if (*p == '0' && - (*(p + 1) == 'x' || *(p + 1) == 'X')) p += 2; + if (*p == '0' && (*(p + 1) == 'x' || *(p + 1) == 'X')) p += 2; } else if (rem >= 2 && base == 2) { - if (*p == '0' && - (*(p + 1) == 'b' || *(p + 1) == 'B')) p += 2; + if (*p == '0' && (*(p + 1) == 'b' || *(p + 1) == 'B')) p += 2; } /* process the digits */ pp = p; while (p < end) { - digit = HAWK_XDIGIT_TO_NUM(*p); - if (digit <= - 1 || digit >= base) break; + digit = HAWK_ZDIGIT_TO_NUM(*p, base); + if (digit >= base) break; n = n * base + digit; p++; } @@ -2701,21 +2699,19 @@ hawk_int_t hawk_bchars_to_int (const hawk_bch_t* str, hawk_oow_t len, int option } else if (rem >= 2 && base == 16) { - if (*p == '0' && - (*(p + 1) == 'x' || *(p + 1) == 'X')) p += 2; + if (*p == '0' && (*(p + 1) == 'x' || *(p + 1) == 'X')) p += 2; } else if (rem >= 2 && base == 2) { - if (*p == '0' && - (*(p + 1) == 'b' || *(p + 1) == 'B')) p += 2; + if (*p == '0' && (*(p + 1) == 'b' || *(p + 1) == 'B')) p += 2; } /* process the digits */ pp = p; while (p < end) { - digit = HAWK_XDIGIT_TO_NUM(*p); - if (digit <= - 1 || digit >= base) break; + digit = HAWK_ZDIGIT_TO_NUM(*p, base); + if (digit >= base) break; n = n * base + digit; p++; }