diff options
author | Rasmus Villemoes <linux@rasmusvillemoes.dk> | 2015-01-14 10:15:57 -0500 |
---|---|---|
committer | David Howells <dhowells@redhat.com> | 2015-01-14 10:15:57 -0500 |
commit | 7fe21291bad93458100fbbf0078d40cdb529a646 (patch) | |
tree | bbc85cda5a693a759053a999c5a6f22e57c0c4ca | |
parent | b2d1965dcea148100ffc4e7199470bf5fad13871 (diff) |
MPILIB: Deobfuscate mpi_cmp
The condition preceding 'return 1;' makes my head hurt. At this point,
we know that u and v have the same sign; if they are negative, they
compare opposite to how their absolute values compare (which
mpihelp_cmp found for us), otherwise cmp itself is the
answer. Negating cmp is ok since mpihelp_cmp returns {-1,0,1};
-INT_MIN==INT_MIN won't bite us.
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Signed-off-by: David Howells <dhowells@redhat.com>
Acked-by: Dmitry Kasatkin <dmitry.kasatkin@gmail.com>
-rw-r--r-- | lib/mpi/mpi-cmp.c | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/lib/mpi/mpi-cmp.c b/lib/mpi/mpi-cmp.c index 1871e7b61ca0..8ed36b8cbe02 100644 --- a/lib/mpi/mpi-cmp.c +++ b/lib/mpi/mpi-cmp.c | |||
@@ -61,10 +61,8 @@ int mpi_cmp(MPI u, MPI v) | |||
61 | if (!usize) | 61 | if (!usize) |
62 | return 0; | 62 | return 0; |
63 | cmp = mpihelp_cmp(u->d, v->d, usize); | 63 | cmp = mpihelp_cmp(u->d, v->d, usize); |
64 | if (!cmp) | 64 | if (u->sign) |
65 | return 0; | 65 | return -cmp; |
66 | if ((cmp < 0 ? 1 : 0) == (u->sign ? 1 : 0)) | 66 | return cmp; |
67 | return 1; | ||
68 | return -1; | ||
69 | } | 67 | } |
70 | EXPORT_SYMBOL_GPL(mpi_cmp); | 68 | EXPORT_SYMBOL_GPL(mpi_cmp); |