Skip to content

Commit 644a1c9

Browse files
author
Jorge Aparicio
committed
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 rust-lang#145
1 parent 0507842 commit 644a1c9

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/int/sdiv.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ macro_rules! divmod {
5555
#[cfg(all(feature = "c", any(target_arch = "x86")))]
5656
() => unsafe { $div(a, b) },
5757
};
58-
*rem = a - (r * b);
58+
// NOTE won't overflow because it's using the result from the
59+
// previous division
60+
*rem = a - r.wrapping_mul(b);
5961
r
6062
}
6163
}

0 commit comments

Comments
 (0)