From bc2fb51c5eb8c7010957cc8f3c8ed7e066c8ea51 Mon Sep 17 00:00:00 2001 From: nobu Date: Fri, 22 Feb 2008 10:50:21 +0000 Subject: [PATCH] * bignum.c (BIGZEROP): fix for longer Bignum zeros. [ruby-Bugs-17454] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15575 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 4 ++++ bignum.c | 14 +++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 82b6fd960a..ad79809812 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Fri Feb 22 19:50:19 2008 Nobuyoshi Nakada + + * bignum.c (BIGZEROP): fix for longer Bignum zeros. [ruby-Bugs-17454] + Fri Feb 22 15:47:36 2008 Tanaka Akira * encoding.c (rb_enc_mbclen): return minlen instead of 1 when diff --git a/bignum.c b/bignum.c index 2119b7d9aa..7220b80a36 100644 --- a/bignum.c +++ b/bignum.c @@ -36,7 +36,19 @@ VALUE rb_cBignum; #define BIGLO(x) ((BDIGIT)((x) & (BIGRAD-1))) #define BDIGMAX ((BDIGIT)-1) -#define BIGZEROP(x) (RBIGNUM_LEN(x) == 0 || (RBIGNUM_LEN(x) == 1 && BDIGITS(x)[0] == 0)) +#define BIGZEROP(x) (RBIGNUM_LEN(x) == 0 || \ + (BDIGITS(x)[0] == 0 && \ + (RBIGNUM_LEN(x) == 1 || bigzero_p(x)))) + +static int +bigzero_p(VALUE x) +{ + long i; + for (i = 0; i < RBIGNUM_LEN(x); ++i) { + if (BDIGITS(x)[i]) return 0; + } + return 1; +} #define RBIGNUM_SET_LEN(b,l) \ ((RBASIC(b)->flags & RBIGNUM_EMBED_FLAG) ? \