From 81d7062685d40fa1e58a291db552b7866e088d33 Mon Sep 17 00:00:00 2001 From: "Richard M. Stallman" Date: Wed, 29 Apr 1998 00:59:22 +0000 Subject: [PATCH] (Flsh, Fash): Handle out-of-range shift counts reasonably. --- src/data.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/data.c b/src/data.c index 18354046210..eb1cbf77bbc 100644 --- a/src/data.c +++ b/src/data.c @@ -2481,8 +2481,12 @@ In this case, the sign bit is duplicated.") CHECK_NUMBER (value, 0); CHECK_NUMBER (count, 1); - if (XINT (count) > 0) + if (XINT (count) >= BITS_PER_EMACS_INT) + XSETINT (val, 0); + else if (XINT (count) > 0) XSETINT (val, XINT (value) << XFASTINT (count)); + else if (XINT (count) <= -BITS_PER_EMACS_INT) + XSETINT (val, XINT (value) < 0 ? -1 : 0); else XSETINT (val, XINT (value) >> -XINT (count)); return val; @@ -2500,8 +2504,12 @@ In this case, zeros are shifted in on the left.") CHECK_NUMBER (value, 0); CHECK_NUMBER (count, 1); - if (XINT (count) > 0) + if (XINT (count) >= BITS_PER_EMACS_INT) + XSETINT (val, 0); + else if (XINT (count) > 0) XSETINT (val, (EMACS_UINT) XUINT (value) << XFASTINT (count)); + else if (XINT (count) <= -BITS_PER_EMACS_INT) + XSETINT (val, 0); else XSETINT (val, (EMACS_UINT) XUINT (value) >> -XINT (count)); return val; -- 2.39.2