From: nobu.nokada@... Date: 2001-12-27T00:08:06+09:00 Subject: [ruby-talk:29444] Re: Is this a bug? At Wed, 26 Dec 2001 23:30:43 +0900, matz@ruby-lang.org (Yukihiro Matsumoto) wrote: > |> |irb(main):008:0> Integer("0\n") > |> |ArgumentError: invalid value for Integer: "0 > |> |" > |> |Is that a bug? > |> > |> No. Integer() checks more strictly. It's the spec. > | > |But Integer("3\n") passes. Isn't it strange? > > You're right. We should allow "0\n". Thank you. Sorry, the former patch was wrong, and dosn't allow "0\n". Index: bignum.c =================================================================== RCS file: /cvs/ruby/src/ruby/bignum.c,v retrieving revision 1.47 diff -u -2 -p -r1.47 bignum.c --- bignum.c 2001/11/19 05:03:02 1.47 +++ bignum.c 2001/12/26 13:47:19 @@ -231,8 +231,5 @@ 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 */ @@ -243,12 +240,20 @@ rb_cstr2inum(str, base) 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)) { @@ -331,7 +336,5 @@ rb_cstr2inum(str, base) 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; } Nobu Nakada