Skip to content

Commit

Permalink
Disable fp exceptions in H5T init code
Browse files Browse the repository at this point in the history
The floating-point datatype initialization code can generate
floating-point exceptions when it trips over signalling NaNs.

The easiest fix for this is to ignore FE_INVALID exceptions while
initializing the floating-point types.
  • Loading branch information
derobins committed Nov 7, 2023
1 parent 0134f60 commit b71b442
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/H5Tinit_float.c
Original file line number Diff line number Diff line change
Expand Up @@ -461,10 +461,17 @@ H5T__init_native_float_types(void)
{
H5T_fpoint_det_t det;
H5T_t *dt = NULL;
int fpe_flags = 0;
herr_t ret_value = SUCCEED;

FUNC_ENTER_PACKAGE

/* Turn off floating-point exceptions while initializing to avoid
* tripping over signalling NaNs while looking at "don't care" bits.
*/
fpe_flags = fegetexcept();
fedisableexcept(FE_INVALID);

/* H5T_NATIVE_FLOAT */

/* Get the type's characteristics */
Expand Down Expand Up @@ -564,6 +571,9 @@ H5T__init_native_float_types(void)
H5T_native_order_g = det.order;

done:
/* Restore the original exceptions */
feenableexcept(fpe_flags);

if (ret_value < 0) {
if (dt != NULL) {
dt->shared = H5FL_FREE(H5T_shared_t, dt->shared);
Expand Down
1 change: 1 addition & 0 deletions src/H5private.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <fenv.h>
#include <float.h>
#include <math.h>
#include <setjmp.h>
Expand Down

0 comments on commit b71b442

Please sign in to comment.