py: Fix bug in mpn_shl (multi-prec int shift left).
Before this patch, eg, 1 << 75 (or any large multiple of 15) was setting
the MSB in the digits, which is outside the valid range of DIG_MASK.
diff --git a/py/mpz.c b/py/mpz.c
index cf02aa2..106e66a 100644
--- a/py/mpz.c
+++ b/py/mpz.c
@@ -89,12 +89,12 @@
mpz_dbl_dig_t d = 0;
for (uint i = jlen; i > 0; i--, idig--, jdig--) {
d |= *jdig;
- *idig = d >> (DIG_SIZE - n_part);
+ *idig = (d >> (DIG_SIZE - n_part)) & DIG_MASK;
d <<= DIG_SIZE;
}
// store remaining bits
- *idig = d >> (DIG_SIZE - n_part);
+ *idig = (d >> (DIG_SIZE - n_part)) & DIG_MASK;
idig -= n_whole - 1;
memset(idig, 0, (n_whole - 1) * sizeof(mpz_dig_t));
@@ -1132,12 +1132,9 @@
lcm(0, 0) = 0
lcm(z, 0) = 0
*/
-mpz_t *mpz_lcm(const mpz_t *z1, const mpz_t *z2)
-{
- // braces below are required for compilation to succeed with CL, see bug report
- // https://connect.microsoft.com/VisualStudio/feedback/details/864169/compilation-error-when-braces-are-left-out-of-single-line-if-statement
- if (z1->len == 0 || z2->len == 0) {
- return mpz_zero();
+mpz_t *mpz_lcm(const mpz_t *z1, const mpz_t *z2) {
+ if (z1->len == 0 || z2->len == 0) {
+ return mpz_zero();
}
mpz_t *gcd = mpz_gcd(z1, z2);