diff options
author | Doug Hogan <[email protected]> | 2019-01-07 00:39:19 -0800 |
---|---|---|
committer | Doug Hogan <[email protected]> | 2019-01-08 01:11:58 -0800 |
commit | 9b0739fd44adfc1a7d5b5b5f26df883cca8b9c41 (patch) | |
tree | a04b5d774c48c32477b0da4dd11faf9515a508d7 /lib/crypto | |
parent | fba65fa791a44b5d0226bd150e8d9accab1e442a (diff) | |
download | otp-9b0739fd44adfc1a7d5b5b5f26df883cca8b9c41.tar.gz otp-9b0739fd44adfc1a7d5b5b5f26df883cca8b9c41.tar.bz2 otp-9b0739fd44adfc1a7d5b5b5f26df883cca8b9c41.zip |
Revamp point2term()
Diffstat (limited to 'lib/crypto')
-rw-r--r-- | lib/crypto/c_src/ec.c | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/lib/crypto/c_src/ec.c b/lib/crypto/c_src/ec.c index 98d3007f13..51da577cd0 100644 --- a/lib/crypto/c_src/ec.c +++ b/lib/crypto/c_src/ec.c @@ -236,22 +236,34 @@ static ERL_NIF_TERM point2term(ErlNifEnv* env, const EC_POINT *point, point_conversion_form_t form) { - unsigned dlen; + ERL_NIF_TERM ret; + size_t dlen; ErlNifBinary bin; + int bin_alloc = 0; - dlen = EC_POINT_point2oct(group, point, form, NULL, 0, NULL); - if (dlen == 0) + if ((dlen = EC_POINT_point2oct(group, point, form, NULL, 0, NULL)) == 0) return atom_undefined; if (!enif_alloc_binary(dlen, &bin)) - return enif_make_badarg(env); + goto err; + bin_alloc = 1; + + if (!EC_POINT_point2oct(group, point, form, bin.data, bin.size, NULL)) + goto err; - if (!EC_POINT_point2oct(group, point, form, bin.data, bin.size, NULL)) { - enif_release_binary(&bin); - return enif_make_badarg(env); - } ERL_VALGRIND_MAKE_MEM_DEFINED(bin.data, bin.size); - return enif_make_binary(env, &bin); + + ret = enif_make_binary(env, &bin); + bin_alloc = 0; + goto done; + + err: + if (bin_alloc) + enif_release_binary(&bin); + ret = enif_make_badarg(env); + + done: + return ret; } int term2point(ErlNifEnv* env, ERL_NIF_TERM term, EC_GROUP *group, EC_POINT **pptr) |