diff options
author | shyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-08-22 01:13:26 +0000 |
---|---|---|
committer | shyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-08-22 01:13:26 +0000 |
commit | 8f72681f1351767c77a7daa5774f7c14e12fd6be (patch) | |
tree | 8ffba1c097a2552fe0f78a68742280ff072670c5 | |
parent | d47a4403bf19818f3bc66bd254f84fa823e88aa9 (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_6@13174 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | bignum.c | 31 | ||||
-rw-r--r-- | version.h | 2 |
3 files changed, 22 insertions, 16 deletions
@@ -1,3 +1,8 @@ +Wed Aug 22 10:11:59 2007 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * bignum.c (rb_cstr_to_inum): check leading non-digits. + [ruby-core:11691] + Wed Aug 22 10:07:48 2007 Nobuyoshi Nakada <nobu@ruby-lang.org> * bignum.c (rb_big_neg): SIGNED_VALUE isn't in 1.8. @@ -346,6 +346,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); @@ -438,7 +445,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); @@ -472,7 +485,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; @@ -480,19 +493,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; @@ -2,7 +2,7 @@ #define RUBY_RELEASE_DATE "2007-08-22" #define RUBY_VERSION_CODE 186 #define RUBY_RELEASE_CODE 20070822 -#define RUBY_PATCHLEVEL 63 +#define RUBY_PATCHLEVEL 64 #define RUBY_VERSION_MAJOR 1 #define RUBY_VERSION_MINOR 8 |