From ee2434851bb22974e0dbfd0cfaf3ebced6b38d68 Mon Sep 17 00:00:00 2001 From: ocean Date: Fri, 21 Oct 2005 06:28:41 +0000 Subject: [PATCH] * bignum.c (bignew_1): convertion from `int' to `char' discards upper bits, (ie. (char)0xff00 -> 0) so it's better to test if nonzero and set 0 or 1 instead of simply casting ... as a flag usage. (but I believe this won't cause actual bug in current implementation) [ruby-dev:27055] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9432 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 8 ++++++++ bignum.c | 8 ++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2adade6fb3..fc85df3e6d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Fri Oct 21 15:23:23 2005 Hirokazu Yamamoto + + * bignum.c (bignew_1): convertion from `int' to `char' discards + upper bits, (ie. (char)0xff00 -> 0) so it's better to test if + nonzero and set 0 or 1 instead of simply casting ... as a flag usage. + (but I believe this won't cause actual bug in current implementation) + [ruby-dev:27055] + Thu Oct 20 22:22:49 2005 Nobuyoshi Nakada * parser.y (struct parser_params): parser never modify input string. diff --git a/bignum.c b/bignum.c index a01c45c7b8..655e22f94e 100644 --- a/bignum.c +++ b/bignum.c @@ -43,7 +43,7 @@ bignew_1(VALUE klass, long len, int sign) { NEWOBJ(big, struct RBignum); OBJSETUP(big, klass, T_BIGNUM); - big->sign = (char)sign; + big->sign = sign?1:0; big->len = len; big->digits = ALLOC_N(BDIGIT, len); @@ -693,7 +693,7 @@ rb_big_to_s(int argc, VALUE *argv, VALUE x) } static unsigned long -big2ulong(VALUE x, char *type, int check) +big2ulong(VALUE x, const char *type, int check) { long len = RBIGNUM(x)->len; BDIGIT_DBL num; @@ -752,7 +752,7 @@ rb_big2long(VALUE x) #if HAVE_LONG_LONG static unsigned LONG_LONG -big2ull(VALUE x, char *type) +big2ull(VALUE x, const char *type) { long len = RBIGNUM(x)->len; BDIGIT_DBL num; @@ -1040,7 +1040,7 @@ bigsub(VALUE x, VALUE y) } } - z = bignew(RBIGNUM(x)->len, (z == 0)?1:0); + z = bignew(RBIGNUM(x)->len, z==0); zds = BDIGITS(z); for (i = 0, num = 0; i < RBIGNUM(y)->len; i++) {