diff options
author | Jakob Kaivo <jkk@ung.org> | 2024-01-31 14:48:09 -0500 |
---|---|---|
committer | Jakob Kaivo <jkk@ung.org> | 2024-01-31 14:48:09 -0500 |
commit | 78033913abfce71b1bcc075ed188c6b6ec087a13 (patch) | |
tree | 2ab38bf89ea46f651c68963c033dac5f345f1e04 | |
parent | 24e5f210091ce984b47fd510217f10245f800f52 (diff) |
add checks for valid exception masks
-rw-r--r-- | src/fenv/_fenv.h | 16 | ||||
-rw-r--r-- | src/fenv/feclearexcept.c | 5 | ||||
-rw-r--r-- | src/fenv/fegetexceptflag.c | 5 | ||||
-rw-r--r-- | src/fenv/feraiseexcept.c | 5 | ||||
-rw-r--r-- | src/fenv/fesetexceptflag.c | 6 | ||||
-rw-r--r-- | src/fenv/fetestexcept.c | 5 |
6 files changed, 37 insertions, 5 deletions
diff --git a/src/fenv/_fenv.h b/src/fenv/_fenv.h new file mode 100644 index 00000000..d07d568f --- /dev/null +++ b/src/fenv/_fenv.h @@ -0,0 +1,16 @@ +#include <fenv.h> +#include "_safety.h" + +#ifdef NDEBUG +#define ASSERT_VALID_EXCEPTION_MASK(_n) (void)(_n) +#define ASSERT_PREVIOUS_FEXCEPT(_f, _e) (void)(_f) +#else +#define ASSERT_VALID_EXCEPTION_MASK(_n) do { \ + if (((_n) & ~(FE_ALL_EXCEPT)) != 0) { \ + __undefined("In call to %s(), exception mask 0x(%jx) is not valid", __func__, (uintmax_t)(_n)); \ + } \ +} while (0) + +/* TODO!!! */ +#define ASSERT_PREVIOUS_FEXCEPT(_f, _e) (void)(_f) +#endif diff --git a/src/fenv/feclearexcept.c b/src/fenv/feclearexcept.c index cf09adcd..4e6e2fc5 100644 --- a/src/fenv/feclearexcept.c +++ b/src/fenv/feclearexcept.c @@ -1,12 +1,15 @@ #include <fenv.h> -#include "_safety.h" +#include "_fenv.h" int feclearexcept(int excepts) { SIGNAL_SAFE(0); + ASSERT_VALID_EXCEPTION_MASK(excepts); return excepts; } +CHECK_1(int, 0, feclearexcept, int) + /* The feclearexcept function clears the supported floating-point exceptions represented by its argument. diff --git a/src/fenv/fegetexceptflag.c b/src/fenv/fegetexceptflag.c index 496b4f9d..921dc1b8 100644 --- a/src/fenv/fegetexceptflag.c +++ b/src/fenv/fegetexceptflag.c @@ -1,13 +1,16 @@ #include <fenv.h> -#include "_safety.h" +#include "_fenv.h" int fegetexceptflag(fexcept_t *flagp, int excepts) { SIGNAL_SAFE(0); + ASSERT_VALID_EXCEPTION_MASK(excepts); (void)flagp; (void)excepts; return 0; } +CHECK_2(int, 0, fegetexceptflag, fexcept_t *, int) + /* The fegetexceptflag function stores an implementation-defined representation of the states of the floating-point status flags indicated by the argument excepts in the diff --git a/src/fenv/feraiseexcept.c b/src/fenv/feraiseexcept.c index cc40934b..4640ecbf 100644 --- a/src/fenv/feraiseexcept.c +++ b/src/fenv/feraiseexcept.c @@ -1,12 +1,15 @@ #include <fenv.h> -#include "_safety.h" +#include "_fenv.h" int feraiseexcept(int excepts) { SIGNAL_SAFE(0); + ASSERT_VALID_EXCEPTION_MASK(excepts); return excepts; } +CHECK_1(int, 0, feraiseexcept, int) + /* The feraiseexcept function raises the supported floating-point exceptions represented by its argument. 178) The order in which these floating-point exceptions are diff --git a/src/fenv/fesetexceptflag.c b/src/fenv/fesetexceptflag.c index d40c7d8c..55f5b1a1 100644 --- a/src/fenv/fesetexceptflag.c +++ b/src/fenv/fesetexceptflag.c @@ -1,13 +1,17 @@ #include <fenv.h> -#include "_safety.h" +#include "_fenv.h" int fesetexceptflag(const fexcept_t *flagp, int excepts) { SIGNAL_SAFE(0); + ASSERT_PREVIOUS_FEXCEPT(flagp, excepts); + ASSERT_VALID_EXCEPTION_MASK(excepts); (void)flagp; (void)excepts; return 0; } +CHECK_2(int, 0, fesetexceptflag, const fexcept_t *, int) + /* The fesetexceptflag function sets the floating-point status flags indicated by the argument excepts to the states stored in the object pointed to by flagp. The value of diff --git a/src/fenv/fetestexcept.c b/src/fenv/fetestexcept.c index 8c4b4bde..371478aa 100644 --- a/src/fenv/fetestexcept.c +++ b/src/fenv/fetestexcept.c @@ -1,12 +1,15 @@ #include <fenv.h> -#include "_safety.h" +#include "_fenv.h" int fetestexcept(int excepts) { SIGNAL_SAFE(0); + ASSERT_VALID_EXCEPTION_MASK(excepts); return excepts; } +CHECK_1(int, 0, fetestexcept, int) + /* The fetestexcept function determines which of a specified subset of the floating- point exception flags are currently set. The excepts argument specifies the floating- |