diff options
author | David N. Welton <[email protected]> | 2014-12-15 17:53:09 +0100 |
---|---|---|
committer | Björn-Egil Dahlberg <[email protected]> | 2015-03-19 11:22:37 +0100 |
commit | 372d62d4e1738431d33c1318be1ee4305c74649d (patch) | |
tree | b193b74946f5430acd73ec40b3e3288bfa485793 /lib/erl_interface/src/legacy | |
parent | 243dc2ff02e3be0af2a2f1aadf7e53f09b4bdbc7 (diff) | |
download | otp-372d62d4e1738431d33c1318be1ee4305c74649d.tar.gz otp-372d62d4e1738431d33c1318be1ee4305c74649d.tar.bz2 otp-372d62d4e1738431d33c1318be1ee4305c74649d.zip |
Do not accept Nan and Infinity values
Erlang does not accept these values, so we return an error in the C
interface rather than letting them through to the Erlang VM, which
rejects the message with a somewhat cryptic "bad external term".
Diffstat (limited to 'lib/erl_interface/src/legacy')
-rw-r--r-- | lib/erl_interface/src/legacy/erl_eterm.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/erl_interface/src/legacy/erl_eterm.c b/lib/erl_interface/src/legacy/erl_eterm.c index 636d26b24b..c167fd1f78 100644 --- a/lib/erl_interface/src/legacy/erl_eterm.c +++ b/lib/erl_interface/src/legacy/erl_eterm.c @@ -26,6 +26,7 @@ #include <stdlib.h> #include <string.h> #include <ctype.h> +#include <math.h> #include "ei_locking.h" #include "ei_resolve.h" @@ -125,6 +126,15 @@ ETERM *erl_mk_float (double d) { ETERM *ep; + /* Erlang does not handle Inf and NaN, so we return an error + * rather than letting the Erlang VM complain about a bad external + * term. */ + switch(fpclassify(d)) { + case FP_NAN: + case FP_INFINITE: + return NULL; + } + ep = erl_alloc_eterm(ERL_FLOAT); ERL_COUNT(ep) = 1; ERL_FLOAT_VALUE(ep) = d; |