diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-07-15 10:05:37 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-07-15 10:05:37 +0000 |
commit | fa1bfaf741b7281418026d10b98d874759a197a4 (patch) | |
tree | 2e3d510a68eee76078153502779833f2cd9262e0 | |
parent | dcfd7ec4b6132b107f71d27df450e823ee44a665 (diff) |
* bignum.c (rb_cstr_to_inum): check leading non-digits.
[ruby-core:11691]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@12795 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | bignum.c | 31 |
2 files changed, 21 insertions, 15 deletions
@@ -1,3 +1,8 @@ +Sun Jul 15 19:05:28 2007 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * bignum.c (rb_cstr_to_inum): check leading non-digits. + [ruby-core:11691] + Sun Jul 15 04:42:20 2007 Nobuyoshi Nakada <nobu@ruby-lang.org> * bignum.c (get2comp): do nothing for empty Bignum. [ruby-dev:31225] @@ -349,6 +349,13 @@ rb_cstr_to_inum(str, base, badcheck) VALUE z; BDIGIT *zds; +#define conv_digit(c) \ + (!ISASCII(c) ? -1 : \ + isdigit(c) ? ((c) - '0') : \ + islower(c) ? ((c) - 'a' + 10) : \ + isupper(c) ? ((c) - 'A' + 10) : \ + -1) + if (!str) { if (badcheck) goto bad; return INT2FIX(0); @@ -441,7 +448,13 @@ rb_cstr_to_inum(str, base, badcheck) } if (*str == '0') { /* squeeze preceeding 0s */ while (*++str == '0'); - --str; + if (!*str) --str; + } + c = *str; + c = conv_digit(c); + if (c < 0 || c >= base) { + if (badcheck) goto bad; + return INT2FIX(0); } len *= strlen(str)*sizeof(char); @@ -475,7 +488,7 @@ rb_cstr_to_inum(str, base, badcheck) z = bignew(len, sign); zds = BDIGITS(z); for (i=len;i--;) zds[i]=0; - while (c = *str++) { + while ((c = *str++) != 0) { if (c == '_') { if (badcheck) { if (nondigit) goto bad; @@ -483,19 +496,7 @@ rb_cstr_to_inum(str, base, badcheck) } continue; } - else if (!ISASCII(c)) { - break; - } - else if (isdigit(c)) { - c -= '0'; - } - else if (islower(c)) { - c -= 'a' - 10; - } - else if (isupper(c)) { - c -= 'A' - 10; - } - else { + else if ((c = conv_digit(c)) < 0) { break; } if (c >= base) break; |