Skip to content

Commit 80ad5cd

Browse files
committed
Fix pointer aliasing issue in modmul & modsqr
1 parent 31d35ae commit 80ad5cd

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

include/ack/bigint.hpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,7 +1022,10 @@ namespace ack {
10221022
constexpr bool operator()(bigint& z, const bigint& x, const bigint& y) const
10231023
{
10241024
bool success = bigint::mul(z, x, y);
1025-
return success && bigint::mod(z, z, *pm);
1025+
bigint u;
1026+
success = success && bigint::mod(u, z, *pm);
1027+
z = std::move( u );
1028+
return success;
10261029
}
10271030
};
10281031

@@ -1031,7 +1034,9 @@ namespace ack {
10311034
constexpr bool operator()(bigint& y, const bigint& x) const
10321035
{
10331036
bool success = bigint::sqr(y, x);
1034-
success = success && bigint::mod(y, y, *pm);
1037+
bigint u; // storing result in temp var avoids pointer aliasing
1038+
success = success && bigint::mod(u, y, *pm);
1039+
y = std::move( u );
10351040
return success;
10361041
}
10371042
};

0 commit comments

Comments
 (0)