* sprintf.c (rb_f_sprintf): Fix a bug caused by an uninitialized

variable v, that a bignum unexpectedly gets converted into a
  string with its higher figures all filled with ./f/7/1,
  depending on the base.  This bug seems to have been introduced
  in rev.1.27.

* sprintf.c (rb_f_sprintf): Use switch instead of a sequence of
  else-if's.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3349 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
knu 2003-01-16 18:48:20 +00:00
Родитель 0df980f610
Коммит b4406583e6
2 изменённых файлов: 40 добавлений и 11 удалений

Просмотреть файл

@ -1,3 +1,14 @@
Fri Jan 17 03:33:42 2003 Akinori MUSHA <knu@iDaemons.org>
* sprintf.c (rb_f_sprintf): Fix a bug caused by an uninitialized
variable v, that a bignum unexpectedly gets converted into a
string with its higher figures all filled with ./f/7/1,
depending on the base. This bug seems to have been introduced
in rev.1.27.
* sprintf.c (rb_f_sprintf): Use switch instead of a sequence of
else-if's.
Wed Jan 15 15:18:38 2003 moumar <moumar@netcourrier.com>
* configure.in (ARCHFILE): set even unless --enable-shared on

Просмотреть файл

@ -319,7 +319,7 @@ rb_f_sprintf(argc, argv)
char *prefix = 0;
int sign = 0;
char sc = 0;
long v;
long v = 0;
int base, bignum = 0;
int len, pos;
@ -338,11 +338,18 @@ rb_f_sprintf(argc, argv)
break;
}
if (flags & FSHARP) {
if (*p == 'o') prefix = "0";
else if (*p == 'x') prefix = "0x";
else if (*p == 'X') prefix = "0X";
else if (*p == 'b') prefix = "0b";
else if (*p == 'B') prefix = "0B";
switch (*p) {
case 'o':
prefix = "0"; break;
case 'x':
prefix = "0x"; break;
case 'X':
prefix = "0X"; break;
case 'b':
prefix = "0b"; break;
case 'B':
prefix = "0B"; break;
}
if (prefix) {
width -= strlen(prefix);
}
@ -369,10 +376,21 @@ rb_f_sprintf(argc, argv)
goto bin_retry;
}
if (*p == 'u' || *p == 'd' || *p == 'i') base = 10;
else if (*p == 'x' || *p == 'X') base = 16;
else if (*p == 'o') base = 8;
else if (*p == 'b' || *p == 'B') base = 2;
switch (*p) {
case 'o':
base = 8; break;
case 'x':
case 'X':
base = 16; break;
case 'b':
case 'B':
base = 2; break;
case 'u':
case 'd':
case 'i':
default:
base = 10; break;
}
if (!bignum) {
if (base == 2) {
val = rb_int2big(v);
@ -510,7 +528,7 @@ rb_f_sprintf(argc, argv)
PUSH(prefix, plen);
}
CHECK(prec - len);
if (v < 0) {
if (!bignum && v < 0) {
char c = '.';
switch (base) {