Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: GnuPG: gcrypt

division by zero optimized away

 

 

GnuPG gcrypt RSS feed   Index | Next | Previous | View Threaded


xi.wang at gmail

Jul 14, 2012, 1:46 PM

Post #1 of 1 (132 views)
Permalink
division by zero optimized away

Hi,

There are two occurrences of intentional division by zero in mpi.
Division by zero is undefined behavior in C, and it may not work
as intended.

1) Division by zero doesn't "provoke a signal" on architectures
like PowerPC.

2) C compilers like clang will optimize away these divisions, even
though the code tries "to make the compiler not remove" them.

gcry_mpi_powm() at mpi/mpi-pow.c:78

if (!msize)
msize = 1 / msize; /* Provoke a signal. */

_gcry_mpih_divrem() at mpi/mpih-div.c:213

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;

How about using something like signal(SIGFPE) instead?

- xi

_______________________________________________
Gcrypt-devel mailing list
Gcrypt-devel [at] gnupg
http://lists.gnupg.org/mailman/listinfo/gcrypt-devel

GnuPG gcrypt RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.