Skip to content

Commit

Permalink
MPILIB: Fix comparison of negative MPIs
Browse files Browse the repository at this point in the history
If u and v both represent negative integers and their limb counts
happen to differ, mpi_cmp will always return a positive value - this
is obviously bogus. u is smaller than v if and only if it is larger in
absolute value.

Signed-off-by: Rasmus Villemoes <[email protected]>
Signed-off-by: David Howells <[email protected]>
Acked-by: Dmitry Kasatkin <[email protected]>
  • Loading branch information
Villemoes authored and dhowells committed Jan 14, 2015
1 parent 98dbbcb commit b9f918a
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/mpi/mpi-cmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ int mpi_cmp(MPI u, MPI v)
if (usize != vsize && !u->sign && !v->sign)
return usize - vsize;
if (usize != vsize && u->sign && v->sign)
return vsize + usize;
return vsize - usize;
if (!usize)
return 0;
cmp = mpihelp_cmp(u->d, v->d, usize);
Expand Down

0 comments on commit b9f918a

Please sign in to comment.