From cd96f5305064ef4eb6551c329c4cd4d2f5e6588d Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Mon, 6 Mar 2017 10:34:27 -0500 Subject: [PATCH] fix infinite recursion in divmoddi4 / mulodi4 on ARMv7-M processors, divmoddi4 was calling mulodi4 and mulodi4 was calling divmoddi4 leading to infinite recursion. This commit breaks the cycle by using wrapping multiplication in divmoddi4. fixes #145 --- library/compiler-builtins/src/int/sdiv.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/library/compiler-builtins/src/int/sdiv.rs b/library/compiler-builtins/src/int/sdiv.rs index 51d9c3769765..d00f89a27881 100644 --- a/library/compiler-builtins/src/int/sdiv.rs +++ b/library/compiler-builtins/src/int/sdiv.rs @@ -55,7 +55,9 @@ macro_rules! divmod { #[cfg(all(feature = "c", any(target_arch = "x86")))] () => unsafe { $div(a, b) }, }; - *rem = a - (r * b); + // NOTE won't overflow because it's using the result from the + // previous division + *rem = a - r.wrapping_mul(b); r } }