MPILIB: Deobfuscate mpi_cmp
authorRasmus Villemoes <linux@rasmusvillemoes.dk>
Wed, 14 Jan 2015 15:15:57 +0000 (15:15 +0000)
committerDavid Howells <dhowells@redhat.com>
Wed, 14 Jan 2015 15:15:57 +0000 (15:15 +0000)
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>
lib/mpi/mpi-cmp.c

index 1871e7b61ca00d2e9a8e926c6754910389596643..8ed36b8cbe02b32b096941cdb196b88b67d66d98 100644 (file)
@@ -61,10 +61,8 @@ int mpi_cmp(MPI u, MPI v)
        if (!usize)
                return 0;
        cmp = mpihelp_cmp(u->d, v->d, usize);
-       if (!cmp)
-               return 0;
-       if ((cmp < 0 ? 1 : 0) == (u->sign ? 1 : 0))
-               return 1;
-       return -1;
+       if (u->sign)
+               return -cmp;
+       return cmp;
 }
 EXPORT_SYMBOL_GPL(mpi_cmp);