Explorar o código

Auto merge of #146 - rust-lang-nursery:gh145, r=alexcrichton

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

r? @alexcrichton
bors %!s(int64=8) %!d(string=hai) anos
pai
achega
8bd620f3e8
Modificáronse 1 ficheiros con 3 adicións e 1 borrados
  1. 3 1
      src/int/sdiv.rs

+ 3 - 1
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
         }
     }