summaryrefslogtreecommitdiff
path: root/bignum.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2001-12-26 17:01:20 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2001-12-26 17:01:20 +0000
commitfb397e335b960cacfa3f5ac84d0eccccc9c222a3 (patch)
tree98f86ef5277febd4b358590c77194458695ec160 /bignum.c
parentc7bfd84967a84a5d838224bf86ece89facce5b5f (diff)
* bignum.c (rb_cstr2inum): allow "0\n" and so on.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_6@1942 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'bignum.c')
-rw-r--r--bignum.c27
1 files changed, 15 insertions, 12 deletions
diff --git a/bignum.c b/bignum.c
index 51be3682d6..ee640fa666 100644
--- a/bignum.c
+++ b/bignum.c
@@ -230,26 +230,31 @@ 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')) {
str += 2;
}
- if (base == 2 && str[0] == '0' && (str[1] == 'b'||str[1] == 'B')) {
+ 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;
}