From 7e8166f5bdb526c021c826943aaf050134cccc83 Mon Sep 17 00:00:00 2001 From: Mark H Weaver Date: Sun, 14 Jul 2013 14:47:10 -0400 Subject: [PATCH] Fix VM 'ash' for right shifts by large amounts. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Fixes . Reported by Göran Weinholt . * 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 | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/libguile/vm-i-scheme.c b/libguile/vm-i-scheme.c index b85d980fd..7402cc1a7 100644 --- a/libguile/vm-i-scheme.c +++ b/libguile/vm-i-scheme.c @@ -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. */ { -- 2.20.1