diff options
author | Lukas Larsson <[email protected]> | 2011-07-05 15:59:24 +0200 |
---|---|---|
committer | Lukas Larsson <[email protected]> | 2011-08-01 16:38:18 +0200 |
commit | a1af48c240079e3923d7eb79511e2539a6713762 (patch) | |
tree | 76a1d84847eaf8dd46e627de459eab9fa5ecd0f5 /lib/asn1 | |
parent | 9368dadeb167451de6c2eee39346377b693b4293 (diff) | |
download | otp-a1af48c240079e3923d7eb79511e2539a6713762.tar.gz otp-a1af48c240079e3923d7eb79511e2539a6713762.tar.bz2 otp-a1af48c240079e3923d7eb79511e2539a6713762.zip |
Add better error messages to nifs
Diffstat (limited to 'lib/asn1')
-rw-r--r-- | lib/asn1/c_src/asn1_erl_nif.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/lib/asn1/c_src/asn1_erl_nif.c b/lib/asn1/c_src/asn1_erl_nif.c index cf3041c45c..2928f098f7 100644 --- a/lib/asn1/c_src/asn1_erl_nif.c +++ b/lib/asn1/c_src/asn1_erl_nif.c @@ -1005,6 +1005,7 @@ int decode_value(ErlNifEnv* env, ERL_NIF_TERM *value, unsigned char *in_buf, static ERL_NIF_TERM encode_per_complete(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) { + ERL_NIF_TERM err_code; ErlNifBinary in_binary; ErlNifBinary out_binary; int complete_len; @@ -1017,6 +1018,10 @@ static ERL_NIF_TERM encode_per_complete(ErlNifEnv* env, int argc, if ((complete_len = complete(&out_binary, in_binary.data, in_binary.size)) <= ASN1_ERROR) { enif_release_binary(&out_binary); + if (complete_len == ASN1_ERROR + ) + err_code = enif_make_uint(env, '1'); + return enif_make_tuple2(env, enif_make_atom(env, "error"), err_code); } if (complete_len < out_binary.size) enif_realloc_binary(&out_binary, complete_len); @@ -1031,13 +1036,13 @@ static ERL_NIF_TERM decode_ber_tlv(ErlNifEnv* env, int argc, unsigned int err_pos = 0, return_code; if (!enif_inspect_iolist_as_binary(env, argv[0], &in_binary)) - return enif_make_atom(env, "badarg"); + return enif_make_badarg(env); if ((return_code = decode_begin(env, &return_term, in_binary.data, in_binary.size, &err_pos)) != ASN1_OK ) - return enif_make_tuple2(env, enif_make_atom(env,"error"), enif_make_tuple3(env, - enif_make_atom(env,""),enif_make_int(env, return_code),enif_make_int(env, err_pos))); + return enif_make_tuple2(env, enif_make_atom(env,"error"), enif_make_tuple2(env, + enif_make_int(env, return_code),enif_make_int(env, err_pos))); return return_term; } |