guile-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Guile-commits] GNU Guile branch, stable-2.0, updated. v2.0.7-3-g2355f01


From: Mark H Weaver
Subject: [Guile-commits] GNU Guile branch, stable-2.0, updated. v2.0.7-3-g2355f01
Date: Fri, 07 Dec 2012 17:02:12 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU Guile".

http://git.savannah.gnu.org/cgit/guile.git/commit/?id=2355f01709eadfd5350c510cdb095b4e3f71f17c

The branch, stable-2.0 has been updated
       via  2355f01709eadfd5350c510cdb095b4e3f71f17c (commit)
      from  e6a730b22a852c4bbbf387907659f284e4da1408 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 2355f01709eadfd5350c510cdb095b4e3f71f17c
Author: Mark H Weaver <address@hidden>
Date:   Fri Dec 7 11:53:00 2012 -0500

    Avoid signed integer overflow in scm_product
    
    * libguile/numbers.c (scm_product): Avoid signed integer overflow, which
      modern C compilers are allowed to assume will never happen, thus
      allowing them to optimize out our overflow checks.
    
    * test-suite/tests/numbers.test (*): Add tests.

-----------------------------------------------------------------------

Summary of changes:
 libguile/numbers.c            |   14 ++++++++++----
 test-suite/tests/numbers.test |   10 ++++++++++
 2 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/libguile/numbers.c b/libguile/numbers.c
index 52e227f..66c95db 100644
--- a/libguile/numbers.c
+++ b/libguile/numbers.c
@@ -7640,10 +7640,16 @@ scm_product (SCM x, SCM y)
       if (SCM_LIKELY (SCM_I_INUMP (y)))
        {
          scm_t_inum yy = SCM_I_INUM (y);
-         scm_t_inum kk = xx * yy;
-         SCM k = SCM_I_MAKINUM (kk);
-         if ((kk == SCM_I_INUM (k)) && (kk / xx == yy))
-           return k;
+#if SCM_I_FIXNUM_BIT < 32 && SCM_HAVE_T_INT64
+          scm_t_int64 kk = xx * (scm_t_int64) yy;
+          if (SCM_FIXABLE (kk))
+            return SCM_I_MAKINUM (kk);
+#else
+          scm_t_inum axx = (xx > 0) ? xx : -xx;
+          scm_t_inum ayy = (yy > 0) ? yy : -yy;
+          if (SCM_MOST_POSITIVE_FIXNUM / axx >= ayy)
+            return SCM_I_MAKINUM (xx * yy);
+#endif
          else
            {
              SCM result = scm_i_inum2big (xx);
diff --git a/test-suite/tests/numbers.test b/test-suite/tests/numbers.test
index ddbd209..66aa01a 100644
--- a/test-suite/tests/numbers.test
+++ b/test-suite/tests/numbers.test
@@ -3070,6 +3070,16 @@
     (pass-if (eqv?   fixnum-min (* (* fixnum-min -1) -1)))
     (pass-if (equal? fixnum-min (* (* fixnum-min -1) -1))))
 
+  (with-test-prefix "signed fixnum overflow"
+    (pass-if (eqv? (* 65536 65536) 4294967296))
+    (pass-if (eqv? (* -65536 65536) -4294967296))
+    (pass-if (eqv? (* 65536 -65536) -4294967296))
+    (pass-if (eqv? (* -65536 -65536) 4294967296))
+    (pass-if (eqv? (* 4294967296 4294967296) 18446744073709551616))
+    (pass-if (eqv? (* -4294967296 4294967296) -18446744073709551616))
+    (pass-if (eqv? (* 4294967296 -4294967296) -18446744073709551616))
+    (pass-if (eqv? (* -4294967296 -4294967296) 18446744073709551616)))
+
   (with-test-prefix "signed zeroes"
     (pass-if (eqv? +0.0 (* +0.0 +0.0)))
     (pass-if (eqv? -0.0 (* -0.0 +0.0)))


hooks/post-receive
-- 
GNU Guile



reply via email to

[Prev in Thread] Current Thread [Next in Thread]