From b8f6db0290fd016239fb50861110515e6cf076b7 Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Fri, 17 Feb 2017 03:48:36 -0500 Subject: [PATCH] Check for 30-bit multiplication overflow --- runtime.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/runtime.c b/runtime.c index e19b36c7..7172c064 100644 --- a/runtime.c +++ b/runtime.c @@ -2533,7 +2533,9 @@ static int Cyc_checked_sub(int x, int y, int *result) static int Cyc_checked_mul(int x, int y, int *result) { *result = x * y; - return (*result != 0 && (*result)/x != y); + return (*result != 0 && (*result)/x != y) || // Overflow + (*result > CYC_FIXNUM_MAX) || + (*result < CYC_FIXNUM_MIN); } #define declare_num_op(FUNC, FUNC_OP, FUNC_APPLY, OP, INT_OP, BN_OP, NO_ARG, ONE_ARG, DIV) \