Fix C-warnings (#10)

* .envrc is not for git

* Fix c code - avoid warnings

* Bump Erlang versions in Github workflows
This commit is contained in:
Hans Svensson 2024-03-19 13:23:23 +01:00 committed by GitHub
parent a3d010ba62
commit 4eb7ec7008
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 15 additions and 11 deletions

1
.envrc
View File

@ -1 +0,0 @@
eval "$(lorri direnv)"

View File

@ -13,9 +13,9 @@ jobs:
strategy: strategy:
matrix: matrix:
otp_vsn: otp_vsn:
- "22.3" - "24.3"
- "23.3" - "25.3"
- "24.0" - "26.2"
os: os:
- ubuntu-latest - ubuntu-latest
steps: steps:

1
.gitignore vendored
View File

@ -1,5 +1,6 @@
.rebar .rebar
.rebar3 .rebar3
.envrc
ebin ebin
*.beam *.beam
*.o *.o

View File

@ -54,9 +54,8 @@ static int enacl_crypto_upgrade(ErlNifEnv* env, void **priv_data,
return 0; return 0;
} }
static int enacl_crypto_unload(ErlNifEnv* env, void **priv_data, static void enacl_crypto_unload(ErlNifEnv* env, void *priv_data) {
ERL_NIF_TERM load_info) { return;
return 0;
} }
/* GENERAL ROUTINES /* GENERAL ROUTINES

View File

@ -221,7 +221,6 @@ ERL_NIF_TERM enacl_crypto_generichash_update(ErlNifEnv *env, int argc,
ERL_NIF_TERM const argv[]) { ERL_NIF_TERM const argv[]) {
ERL_NIF_TERM ret; ERL_NIF_TERM ret;
ErlNifBinary data; ErlNifBinary data;
unsigned int data_size;
enacl_generichash_ctx *obj = NULL; enacl_generichash_ctx *obj = NULL;
// Validate the arguments // Validate the arguments

View File

@ -20,7 +20,7 @@ ERL_NIF_TERM enacl_crypto_kdf_CONTEXTBYTES(ErlNifEnv *env, int argc,
ERL_NIF_TERM enacl_crypto_kdf_derive_from_key(ErlNifEnv *env, int argc, ERL_NIF_TERM enacl_crypto_kdf_derive_from_key(ErlNifEnv *env, int argc,
ERL_NIF_TERM const argv[]) { ERL_NIF_TERM const argv[]) {
ErlNifBinary m, c, r; ErlNifBinary m, c, r;
uint64_t id; ErlNifUInt64 id;
// Validate the arguments // Validate the arguments
if ((argc != 3) || if ((argc != 3) ||

View File

@ -90,7 +90,7 @@ ERL_NIF_TERM enacl_crypto_box(ErlNifEnv *env, int argc,
goto bad_arg; goto bad_arg;
if (!enif_alloc_binary(padded_msg.size, &result)) { if (!enif_alloc_binary(padded_msg.size, &result)) {
goto done; goto err;
} }
if (0 != crypto_box(result.data, padded_msg.data, padded_msg.size, nonce.data, if (0 != crypto_box(result.data, padded_msg.data, padded_msg.size, nonce.data,

View File

@ -227,11 +227,13 @@ ERL_NIF_TERM enacl_crypto_secretstream_xchacha20poly1305_init_pull(
obj->state = enif_alloc(crypto_secretstream_xchacha20poly1305_statebytes()); obj->state = enif_alloc(crypto_secretstream_xchacha20poly1305_statebytes());
if (obj->state == NULL) { if (obj->state == NULL) {
ret = enacl_internal_error(env);
goto release; goto release;
} }
obj->alive = 1; obj->alive = 1;
if ((obj->mtx = enif_mutex_create("enacl.secretstream")) == NULL) { if ((obj->mtx = enif_mutex_create("enacl.secretstream")) == NULL) {
ret = enacl_internal_error(env);
goto free; goto free;
} }

View File

@ -62,6 +62,7 @@ ERL_NIF_TERM enacl_crypto_sign_init(ErlNifEnv *env, int argc,
obj->alive = 0; obj->alive = 0;
obj->state = enif_alloc(crypto_sign_statebytes()); obj->state = enif_alloc(crypto_sign_statebytes());
if (obj->state == NULL) { if (obj->state == NULL) {
ret = enacl_internal_error(env);
goto release; goto release;
} }
obj->alive = 1; obj->alive = 1;
@ -82,6 +83,7 @@ ERL_NIF_TERM enacl_crypto_sign_init(ErlNifEnv *env, int argc,
bad_arg: bad_arg:
return enif_make_badarg(env); return enif_make_badarg(env);
free: free:
ret = enacl_internal_error(env);
if (obj->alive) if (obj->alive)
if (obj->state != NULL) { if (obj->state != NULL) {
sodium_memzero(obj->state, crypto_sign_statebytes()); sodium_memzero(obj->state, crypto_sign_statebytes());
@ -285,7 +287,9 @@ enacl_crypto_sign_ed25519_public_to_curve25519(ErlNifEnv *env, int argc,
return enacl_internal_error(env); return enacl_internal_error(env);
} }
crypto_sign_ed25519_pk_to_curve25519(curve25519_pk.data, ed25519_pk.data); if (crypto_sign_ed25519_pk_to_curve25519(curve25519_pk.data, ed25519_pk.data) != 0) {
return enacl_internal_error(env);
}
return enif_make_binary(env, &curve25519_pk); return enif_make_binary(env, &curve25519_pk);
} }