Re: enif_make_double returns invalid term for 'nan'
Heinz Nikolaus Gies <[email protected]>
| Newsgroups | gmane.comp.lang.erlang.bugs |
|---|---|
| Message-ID | <[email protected]> |
Hi Mikael, thank for the clarification. That makes sense, I find 2) actually more troublesome since I went to consult the documents to be sure it’s not a defined behavior. What was a bit more concerning was that that it returned a value that breaks transparently breaks other erlang functions. Perhaps simply returning a bad_arg would make a lot more sense? --- Cheers, Heinz Nikolaus Gies [email protected] > On Mar 1, 2015, at 13:02, Mikael Pettersson <[email protected]> wrote: > > Heinz Nikolaus Gies writes: >> When enif_make_double gets a nan value passed as the double argument it returns a invalid term, this term can neither be printed (via the fmt*) functions nor can it be deserialized by binary_to_term when serializing it the following binary is generated: >> >> 6> io:format("~p~n", [term_to_binary(V)]). >> <<131,99,110,97,110,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0>> >> >> V is the double returned by enif_make_double > > There are two issues here: > 1. the VM disallows INFs and NANs, but NIF authors may not be aware of that > 2. enif_make_double() SHOULD reject non-finite doubles but it doesn't, and > its documentation doesn't mention any failure modes; returning THE_NON_VALUE > may not be detected as a failure by the NIF and so this non-value may leak > into aggregates (lists or tuples) where it will totally break things > > When looking at this I noticed that enif_make_atom() also has problems: it > may fail and return THE_NON_VALUE if the resulting atom would be too long, > but the documentation doesn't mention this possibility so the NIF might > continue and store this non-value in aggregates before returning. > > The OTP folks need to straighten up error handling in the enif_make_*() > functions. _______________________________________________ erlang-bugs mailing list [email protected] http://erlang.org/mailman/listinfo/erlang-bugs
signature.asc
(application/pgp-signature, 801 B)
-----BEGIN PGP SIGNATURE----- iQIcBAEBCgAGBQJU8x6sAAoJEKM5c9dFK2+YK8wP/3EwVGUYro0wDMwNOSclfvVt ychjKSCRrYmLfUbSeRyLS5V26ggTFXd1eK7/YbnA91ULckCX0l+EYkpZwvNMyHqL Atxbbx6XczVKjbIQuqnLX17Y7YiKKZfm4Ygl7L3QW70atf1Mkg3LQArFRLI1rPCl N5d8wFJYVtR8uy1Zui4KzfoYKixELZkKl4zxwOs5KqcSHOrBXtu31mC8qLlcN5/X J+dUbGscPCdVp1VmC1DIojP17FMoxsEwNaNIRVOoEZD6hEJVrNmMcZZaW/zDAijQ 8z1OzH0XkmjqVd81XPAld42YG3ms5ebmj1cJyZiwnOECaNMwaUqTUqsQeBNHqIKG vK7bMQhAEmanlLp7Oj/Xhtom5fF2+e09RawVSA+5AjXxMv4ZVvLFNcHdCFI9Keb2 rbhwVBxg4PS03woGSZgnSPQF3obo6pIHxttlVeyjdtnaB53KsKbdd1eOzlmbVFvi cWHvk9+9OUM0DkOZgaDG8Eg2JCns01SnfV2SU8dh+180XAozKZ7QdQsO+NF5O5ta Be2H5qyL3aHiH2pq2RuNU/Y8NH8dqTJxWQ6lOeiW6/zD6rd/VKjiENw4KqHQDMRj XQXCoM8sopsKX2/KgLc3fuTBvWQci5pGIBcO9YCqTRsS6TGKFkkdD9Ohc7jE/wbc EaeTc2RzaDswuLkzsBsX =5D8B -----END PGP SIGNATURE-----