[PATCH] Replace division by zero with assert failure
Vladimir 'φ-coder/phcoder' Serbinenko
phcoder at gmail.com
Fri Nov 8 16:58:54 CET 2013
C specification says that division by zero is undefined and may not
provoke a signal. So it would be more appropriate to use gcry_assert
diff --git a/grub-core/lib/libgcrypt/mpi/mpi-pow.c
b/grub-core/lib/libgcrypt/mpi/mpi-pow.c
index a63fc6d..f5d2116 100644
--- a/grub-core/lib/libgcrypt/mpi/mpi-pow.c
+++ b/grub-core/lib/libgcrypt/mpi/mpi-pow.c
@@ -76,8 +76,7 @@ gcry_mpi_powm (gcry_mpi_t res,
rp = res->d;
ep = expo->d;
- if (!msize)
- msize = 1 / msize; /* Provoke a signal. */
+ gcry_assert (msize != 0);
if (!esize)
{
diff --git a/grub-core/lib/libgcrypt/mpi/mpih-div.c
b/grub-core/lib/libgcrypt/mpi/mpih-div.c
index 224b810..07dcf54 100644
--- a/grub-core/lib/libgcrypt/mpi/mpih-div.c
+++ b/grub-core/lib/libgcrypt/mpi/mpih-div.c
@@ -212,9 +212,9 @@ _gcry_mpih_divrem( mpi_ptr_t qp, mpi_size_t
qextra_limbs,
switch(dsize) {
case 0:
- /* We are asked to divide by zero, so go ahead and do it! (To make
- the compiler not remove this statement, return the value.) */
- return 1 / dsize;
+ /* We are asked to divide by zero. */
+ gcry_assert (0);
+ return 0;
case 1:
{
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 291 bytes
Desc: OpenPGP digital signature
URL: </pipermail/attachments/20131108/fdcdd8ba/attachment.sig>
More information about the Gcrypt-devel
mailing list