diff options
author | Doug Hogan <[email protected]> | 2019-01-03 20:36:58 -0800 |
---|---|---|
committer | Doug Hogan <[email protected]> | 2019-01-08 01:11:57 -0800 |
commit | afda6208baa01d86efa52a31504293af2e5ec1f5 (patch) | |
tree | 2737e3bbd7fe4e435eb6e3f43635d111a807c719 | |
parent | 03644ba9bcab05568870291ac5f4687c813688f5 (diff) | |
download | otp-afda6208baa01d86efa52a31504293af2e5ec1f5.tar.gz otp-afda6208baa01d86efa52a31504293af2e5ec1f5.tar.bz2 otp-afda6208baa01d86efa52a31504293af2e5ec1f5.zip |
Revamp zero_terminate()
-rw-r--r-- | lib/crypto/c_src/engine.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/lib/crypto/c_src/engine.c b/lib/crypto/c_src/engine.c index 56029638d4..cec525fc80 100644 --- a/lib/crypto/c_src/engine.c +++ b/lib/crypto/c_src/engine.c @@ -84,12 +84,16 @@ char *get_key_password(ErlNifEnv *env, ERL_NIF_TERM key) { } static int zero_terminate(ErlNifBinary bin, char **buf) { - *buf = enif_alloc(bin.size+1); - if (!*buf) - return 0; + if ((*buf = enif_alloc(bin.size + 1)) == NULL) + goto err; + memcpy(*buf, bin.data, bin.size); - *(*buf+bin.size) = 0; + *(*buf + bin.size) = 0; + return 1; + + err: + return 0; } #endif /* HAS_ENGINE_SUPPORT */ |