Skip to content

Commit 708380d

Browse files
committed
* 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_5@12986 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent db9f4b5 commit 708380d

File tree

3 files changed

+22
-16
lines changed

3 files changed

+22
-16
lines changed

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
Thu Aug 16 05:02:39 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
2+
3+
* bignum.c (rb_cstr_to_inum): check leading non-digits.
4+
[ruby-core:11691]
5+
16
Thu Aug 16 05:00:01 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
27

38
* numeric.c (fix_pow): 0**2 should not raise floating point

bignum.c

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,13 @@ rb_cstr_to_inum(str, base, badcheck)
331331
VALUE z;
332332
BDIGIT *zds;
333333

334+
#define conv_digit(c) \
335+
(!ISASCII(c) ? -1 : \
336+
isdigit(c) ? ((c) - '0') : \
337+
islower(c) ? ((c) - 'a' + 10) : \
338+
isupper(c) ? ((c) - 'A' + 10) : \
339+
-1)
340+
334341
if (!str) {
335342
if (badcheck) goto bad;
336343
return INT2FIX(0);
@@ -423,7 +430,13 @@ rb_cstr_to_inum(str, base, badcheck)
423430
}
424431
if (*str == '0') { /* squeeze preceeding 0s */
425432
while (*++str == '0');
426-
--str;
433+
if (!*str) --str;
434+
}
435+
c = *str;
436+
c = conv_digit(c);
437+
if (c < 0 || c >= base) {
438+
if (badcheck) goto bad;
439+
return INT2FIX(0);
427440
}
428441
len *= strlen(str)*sizeof(char);
429442

@@ -457,27 +470,15 @@ rb_cstr_to_inum(str, base, badcheck)
457470
z = bignew(len, sign);
458471
zds = BDIGITS(z);
459472
for (i=len;i--;) zds[i]=0;
460-
while (c = *str++) {
473+
while ((c = *str++) != 0) {
461474
if (c == '_') {
462475
if (badcheck) {
463476
if (nondigit) goto bad;
464477
nondigit = c;
465478
}
466479
continue;
467480
}
468-
else if (!ISASCII(c)) {
469-
break;
470-
}
471-
else if (isdigit(c)) {
472-
c -= '0';
473-
}
474-
else if (islower(c)) {
475-
c -= 'a' - 10;
476-
}
477-
else if (isupper(c)) {
478-
c -= 'A' - 10;
479-
}
480-
else {
481+
else if ((c = conv_digit(c)) < 0) {
481482
break;
482483
}
483484
if (c >= base) break;

version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#define RUBY_RELEASE_DATE "2007-08-16"
33
#define RUBY_VERSION_CODE 185
44
#define RUBY_RELEASE_CODE 20070816
5-
#define RUBY_PATCHLEVEL 71
5+
#define RUBY_PATCHLEVEL 72
66

77
#define RUBY_VERSION_MAJOR 1
88
#define RUBY_VERSION_MINOR 8

0 commit comments

Comments
 (0)