From 068e5d0b63b11a969c077c1091d32ee9231206bf Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 27 Nov 2007 17:42:12 +0000 Subject: * bignum.c (big2str_find_n1): removed extraneous element. [ruby-dev:32351], [ruby-dev:32365] * bignum.c (big2str_find_n1): returns necessary digits now. * sprintf.c (remove_sign_bits): extends sign bit first. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@14034 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- sprintf.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'sprintf.c') diff --git a/sprintf.c b/sprintf.c index 62731a5f2..ed02e01ae 100644 --- a/sprintf.c +++ b/sprintf.c @@ -19,6 +19,8 @@ #include #define BIT_DIGITS(N) (((N)*146)/485 + 1) /* log2(10) =~ 146/485 */ +#define BITSPERDIG (SIZEOF_BDIGITS*CHAR_BIT) +#define EXTENDSIGN(n, l) (((~0 << (n)) >> (((n)*(l)) % BITSPERDIG)) & ~(~0 << (n))) static void fmt_setup(char*,int,int,int,int); @@ -35,7 +37,7 @@ remove_sign_bits(char *str, int base) } } else if (base == 8) { - if (*t == '3') t++; + *t |= EXTENDSIGN(3, strlen(t)); while (*t == '7') { t++; } @@ -662,7 +664,7 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt) val = rb_big_clone(val); rb_big_2comp(val); } - tmp1 = tmp = rb_big2str0(val, base, Qtrue); + tmp1 = tmp = rb_big2str0(val, base, RBIGNUM_SIGN(val)); s = RSTRING_PTR(tmp); if (*s == '-') { if (base == 10) { @@ -695,7 +697,7 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt) if (*p == 'X') { char *pp = s; int c; - while (c = (int)*pp) { + while ((c = (int)(unsigned char)*pp) != 0) { *pp = rb_enc_toupper(c, enc); pp++; } -- cgit