diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2001-12-26 17:01:20 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2001-12-26 17:01:20 +0000 |
commit | d0c78c8567a009626191ea1383599624e169966a (patch) | |
tree | 6b0066ce29a9d9d3661f74719f507c56303e8221 /bignum.c | |
parent | 36e891304c0f1619808ff2d3afaf0920e23470c8 (diff) | |
download | ruby-d0c78c8567a009626191ea1383599624e169966a.tar.gz |
* bignum.c (rb_cstr2inum): allow "0\n" and so on.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1942 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'bignum.c')
-rw-r--r-- | bignum.c | 25 |
1 files changed, 14 insertions, 11 deletions
@@ -230,10 +230,7 @@ rb_cstr2inum(str, base) } } if (base == 8) { - while (*str == '0') str++; - if (!*str) return INT2FIX(0); - while (*str == '_') str++; - len = 3*strlen(str)*sizeof(char); + len = 3; } else { /* base == 10, 2 or 16 */ if (base == 16 && str[0] == '0' && (str[1] == 'x'||str[1] == 'X')) { @@ -242,14 +239,22 @@ rb_cstr2inum(str, base) else if (base == 2 && str[0] == '0' && (str[1] == 'b'||str[1] == 'B')) { str += 2; } - while (*str && *str == '0') str++; + len = 4; + } + if (*str == '0') { + do str++; while (*str == '0'); + if (!*str) return INT2FIX(0); + while (*str == '_') str++; + if (!*str) str--; if (ISSPACE(*str)) { - if (badcheck) goto bad; + if (badcheck) { + while (ISSPACE(*str)) str++; + if (*str) goto bad; + } return INT2FIX(0); } - if (!*str) str--; - len = 4*strlen(str)*sizeof(char); } + len *= strlen(str)*sizeof(char); if (len <= (sizeof(VALUE)*CHAR_BIT)) { unsigned long val = strtoul((char*)str, &end, base); @@ -330,9 +335,7 @@ rb_cstr2inum(str, base) if (badcheck) { str--; if (s+1 < str && str[-1] == '_') goto bad; - if (ISSPACE(c)) { - while (*str && ISSPACE(*str)) str++; - } + while (*str && ISSPACE(*str)) str++; if (*str) goto bad; } |