Fix VM 'ash' for right shifts by large amounts.
authorMark H Weaver <mhw@netris.org>
Sun, 14 Jul 2013 18:47:10 +0000 (14:47 -0400)
committerMark H Weaver <mhw@netris.org>
Sun, 14 Jul 2013 18:47:10 +0000 (14:47 -0400)
Fixes <http://bugs.gnu.org/14864>.
Reported by Göran Weinholt <goran@weinholt.se>.

* libguile/vm-i-scheme.c (ash): Fallback to 'scm_ash' for right shifts
  with counts >= SCM_I_FIXNUM_BIT, since '>>' is not guaranteed to work
  correctly for large counts.

libguile/vm-i-scheme.c

index b85d980..7402cc1 100644 (file)
@@ -388,8 +388,12 @@ VM_DEFINE_FUNCTION (159, ash, "ash", 2)
   if (SCM_I_INUMP (x) && SCM_I_INUMP (y))
     {
       if (SCM_I_INUM (y) < 0)
-        /* Right shift, will be a fixnum. */
-        RETURN (SCM_I_MAKINUM (SCM_I_INUM (x) >> -SCM_I_INUM (y)));
+        {
+          /* Right shift, will be a fixnum. */
+          if (SCM_I_INUM (y) > -SCM_I_FIXNUM_BIT)
+            RETURN (SCM_I_MAKINUM (SCM_I_INUM (x) >> -SCM_I_INUM (y)));
+          /* fall through */
+        }
       else
         /* Left shift. See comments in scm_ash. */
         {