aboutsummaryrefslogtreecommitdiffstats
path: root/bignum.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-06-22 15:52:36 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-06-22 15:52:36 +0000
commitf175d5259c5b1b5ba2de7301ea92deffcbb639fd (patch)
tree86fcbfe05a2445399b5bb306f599c5f91ae8fb1d /bignum.c
parent31415e58092661347831b687f2db705c89addd9b (diff)
downloadruby-f175d5259c5b1b5ba2de7301ea92deffcbb639fd.tar.gz
* bignum.c (bytes_zero_p): Extracted from bary_pack.
(bary_pack): Use bytes_zero_p. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41578 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'bignum.c')
-rw-r--r--bignum.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/bignum.c b/bignum.c
index c3cc2c292c..ab104b4a85 100644
--- a/bignum.c
+++ b/bignum.c
@@ -124,6 +124,15 @@ rb_big_dump(VALUE x)
#endif
static int
+bytes_zero_p(unsigned char *p, size_t n)
+{
+ while (n--)
+ if (*p++)
+ return 0;
+ return 1;
+}
+
+static int
bary_zero_p(BDIGIT *xds, size_t nx)
{
if (nx == 0)
@@ -929,13 +938,11 @@ bary_pack(int sign, BDIGIT *ds, size_t num_bdigits, void *words, size_t numwords
if (sign < 0 && (flags & INTEGER_PACK_2COMP)) {
int zero_p = bytes_2comp(words, dst_size);
if (zero_p && overflow) {
- unsigned char *p = (unsigned char *)dp + dst_size;
- unsigned char *e = (unsigned char *)dp + src_size;
- if (p < e && *p++ == 1) {
- while (p < e && *p == 0)
- p++;
- if (p == e)
- overflow = 0;
+ unsigned char *p = (unsigned char *)dp;
+ if (dst_size < src_size &&
+ p[dst_size] == 1 &&
+ bytes_zero_p(p+dst_size+1, src_size-dst_size-1)) {
+ overflow = 0;
}
}
}