diff --git a/docs/api/10-bsl-developers.md b/docs/api/10-bsl-developers.md index 6d125ef..373a8fe 100644 --- a/docs/api/10-bsl-developers.md +++ b/docs/api/10-bsl-developers.md @@ -226,11 +226,11 @@ When heap memory is needed at BSL runtime, the following macros are used and hav To help with the error reporting conventions above, the following macros can be used to simplify function precondition checking. The precondition checks (on function parameters or on any other state generally) should be the first thing inside the function definition. -- [CHKRET(cond, val)](@ref CHKRET) for general error values -- [CHKNULL(cond)](@ref CHKNULL) when the function has a pointer return type -- [CHKERR1(cond)](@ref CHKERR1) when the function has an `int` return type -- [CHKVOID(cond)](@ref CHKVOID) when the function has an `void` return type -- [CHKFALSE(cond)](@ref CHKFALSE) when the function has an `bool` return type +- [BSL_CHKRET(cond, val)](@ref BSL_CHKRET) for general error values +- [BSL_CHKNULL(cond)](@ref BSL_CHKNULL) when the function has a pointer return type +- [BSL_CHKERR1(cond)](@ref BSL_CHKERR1) when the function has an `int` return type +- [BSL_CHKVOID(cond)](@ref BSL_CHKVOID) when the function has an `void` return type +- [BSL_CHKFALSE(cond)](@ref BSL_CHKFALSE) when the function has an `bool` return type # Enumerations diff --git a/src/BPSecLib_Private.h b/src/BPSecLib_Private.h index 7af6cb3..4107f51 100644 --- a/src/BPSecLib_Private.h +++ b/src/BPSecLib_Private.h @@ -129,25 +129,25 @@ typedef enum * @param val The return value if the check fails. * @deprecated */ -#define CHKRET(cond, val) \ - if (!LIKELY(cond)) \ - { \ - return val; \ +#define BSL_CHKRET(cond, val) \ + if (!LIKELY(cond)) \ + { \ + return val; \ } /// Return from void functions if condition fails. -#define CHKVOID(cond) CHKRET(cond, ) +#define BSL_CHKVOID(cond) BSL_CHKRET(cond, ) /// Return a null pointer if condition fails. -#define CHKNULL(cond) CHKRET(cond, NULL) +#define BSL_CHKNULL(cond) BSL_CHKRET(cond, NULL) /// Return false if condition fails. -#define CHKFALSE(cond) CHKRET(cond, false) +#define BSL_CHKFALSE(cond) BSL_CHKRET(cond, false) /// Return the error value 1 if condition fails. -#define CHKERR1(cond) CHKRET(cond, 1) +#define BSL_CHKERR1(cond) BSL_CHKRET(cond, 1) /** Check a value for non-zero and return that value. * @warning The parameter is evaluated twice so should be a simple variable. * * @param value The value to check and conditionally return. */ -#define CHKERRVAL(value) CHKRET(!(value), (value)) +#define BSL_CHKERRVAL(value) BSL_CHKRET(!(value), (value)) /** @brief Codes indicating the fate of a block if a security operation over it fails * diff --git a/src/backend/LoggingStderr.c b/src/backend/LoggingStderr.c index f6f9707..a603031 100644 --- a/src/backend/LoggingStderr.c +++ b/src/backend/LoggingStderr.c @@ -261,8 +261,8 @@ void BSL_closelog(void) int BSL_LogGetSeverity(int *severity, const char *name) { - CHKERR1(severity) - CHKERR1(name) + BSL_CHKERR1(severity); + BSL_CHKERR1(name); for (size_t ix = 0; ix < sizeof(sev_names) / sizeof(const char *); ++ix) { diff --git a/src/mock_bpa/ctr.c b/src/mock_bpa/ctr.c index 7aef535..d17a3b3 100644 --- a/src/mock_bpa/ctr.c +++ b/src/mock_bpa/ctr.c @@ -28,7 +28,7 @@ void mock_bpa_ctr_init(mock_bpa_ctr_t *ctr) { - CHKVOID(ctr); + BSL_CHKVOID(ctr); memset(ctr, 0, sizeof(*ctr)); BSL_Data_Init(&(ctr->encoded)); @@ -41,8 +41,8 @@ void mock_bpa_ctr_init(mock_bpa_ctr_t *ctr) void mock_bpa_ctr_init_move(mock_bpa_ctr_t *ctr, mock_bpa_ctr_t *src) { - CHKVOID(ctr); - CHKVOID(src); + BSL_CHKVOID(ctr); + BSL_CHKVOID(src); BSL_Data_InitMove(&(ctr->encoded), &(src->encoded)); ctr->bundle = src->bundle; @@ -54,7 +54,7 @@ void mock_bpa_ctr_init_move(mock_bpa_ctr_t *ctr, mock_bpa_ctr_t *src) void mock_bpa_ctr_deinit(mock_bpa_ctr_t *ctr) { - CHKVOID(ctr); + BSL_CHKVOID(ctr); BSL_Data_Deinit(&(ctr->encoded)); if (ctr->bundle) @@ -66,7 +66,7 @@ void mock_bpa_ctr_deinit(mock_bpa_ctr_t *ctr) int mock_bpa_decode(mock_bpa_ctr_t *ctr) { - CHKERR1(ctr); + BSL_CHKERR1(ctr); MockBPA_Bundle_t *bundle = ctr->bundle_ref.data; if (ctr->bundle_ref.data) @@ -110,9 +110,9 @@ M_ALGO_DEF(MockBPA_BlockList, M_DEQUE_OPLIST(MockBPA_BlockList, M_OPEXTEND(M_POD int mock_bpa_encode(mock_bpa_ctr_t *ctr) { - CHKERR1(ctr); + BSL_CHKERR1(ctr); MockBPA_Bundle_t *bundle = ctr->bundle_ref.data; - CHKERR1(bundle); + BSL_CHKERR1(bundle); // TODO this is not really defined by BPSec or BPv7 MockBPA_BlockList_sort(bundle->blocks); diff --git a/src/mock_bpa/decode.c b/src/mock_bpa/decode.c index ebf75e8..ff429f7 100644 --- a/src/mock_bpa/decode.c +++ b/src/mock_bpa/decode.c @@ -150,8 +150,8 @@ int bsl_mock_decode_eid_from_ctx(QCBORDecodeContext *dec, BSL_HostEID_t *eid) int bsl_mock_decode_primary(QCBORDecodeContext *dec, MockBPA_PrimaryBlock_t *blk) { // GCOV_EXCL_START - CHKERR1(dec); - CHKERR1(blk); + BSL_CHKERR1(dec); + BSL_CHKERR1(blk); // GCOV_EXCL_STOP const size_t begin = QCBORDecode_Tell(dec); @@ -236,8 +236,8 @@ int bsl_mock_decode_primary(QCBORDecodeContext *dec, MockBPA_PrimaryBlock_t *blk int bsl_mock_decode_canonical(QCBORDecodeContext *dec, MockBPA_CanonicalBlock_t *blk) { // GCOV_EXCL_START - CHKERR1(dec); - CHKERR1(blk); + BSL_CHKERR1(dec); + BSL_CHKERR1(blk); // GCOV_EXCL_STOP const size_t begin = QCBORDecode_Tell(dec); @@ -299,8 +299,8 @@ int bsl_mock_decode_canonical(QCBORDecodeContext *dec, MockBPA_CanonicalBlock_t int bsl_mock_decode_bundle(QCBORDecodeContext *dec, MockBPA_Bundle_t *bundle) { // GCOV_EXCL_START - CHKERR1(dec); - CHKERR1(bundle); + BSL_CHKERR1(dec); + BSL_CHKERR1(bundle); // GCOV_EXCL_STOP QCBORItem decitem; diff --git a/src/mock_bpa/eid.c b/src/mock_bpa/eid.c index 4cfda1a..94052ab 100644 --- a/src/mock_bpa/eid.c +++ b/src/mock_bpa/eid.c @@ -35,13 +35,13 @@ void bsl_mock_eid_init(bsl_mock_eid_t *eid) { - CHKVOID(eid); + BSL_CHKVOID(eid); memset(eid, 0, sizeof(bsl_mock_eid_t)); } void bsl_mock_eid_deinit(bsl_mock_eid_t *eid) { - CHKVOID(eid); + BSL_CHKVOID(eid); switch (eid->scheme) { case BSL_MOCK_EID_IPN: @@ -55,7 +55,7 @@ void bsl_mock_eid_deinit(bsl_mock_eid_t *eid) int MockBPA_EID_Init(void *user_data _U_, BSL_HostEID_t *eid) { - CHKERR1(eid); + BSL_CHKERR1(eid); memset(eid, 0, sizeof(BSL_HostEID_t)); eid->handle = BSL_MALLOC(sizeof(bsl_mock_eid_t)); if (!(eid->handle)) @@ -68,7 +68,7 @@ int MockBPA_EID_Init(void *user_data _U_, BSL_HostEID_t *eid) void MockBPA_EID_Deinit(void *user_data _U_, BSL_HostEID_t *eid) { - CHKVOID(eid); + BSL_CHKVOID(eid); if (eid->handle) { bsl_mock_eid_deinit(eid->handle); @@ -79,8 +79,8 @@ void MockBPA_EID_Deinit(void *user_data _U_, BSL_HostEID_t *eid) int mock_bpa_eid_from_text(BSL_HostEID_t *eid, const char *text, void *user_data _U_) { - CHKERR1(eid); - CHKERR1(text); + BSL_CHKERR1(eid); + BSL_CHKERR1(text); // any spaces are invalid URI // agrees with isspace() @@ -174,8 +174,8 @@ int mock_bpa_eid_from_text(BSL_HostEID_t *eid, const char *text, void *user_data // int mock_bpa_eid_to_text(string_t out, const BSL_HostEID_t *eid, void *user_data _U_) // { -// CHKERR1(eid); -// CHKERR1(eid->handle); +// BSL_CHKERR1(eid); +// BSL_CHKERR1(eid->handle); // bsl_mock_eid_t *obj = (bsl_mock_eid_t *)eid->handle; // switch (obj->scheme) diff --git a/src/mock_bpa/eidpat.c b/src/mock_bpa/eidpat.c index 75bdd28..2d54df8 100644 --- a/src/mock_bpa/eidpat.c +++ b/src/mock_bpa/eidpat.c @@ -283,9 +283,9 @@ void bsl_mock_eidpat_item_deinit(bsl_mock_eidpat_item_t *obj) int mock_bpa_eidpat_item_from_text(bsl_mock_eidpat_item_t *item, const char *text, const char **endptr) { // GCOV_EXCL_START - CHKERR1(item); - CHKERR1(text); - CHKERR1(endptr); + BSL_CHKERR1(item); + BSL_CHKERR1(text); + BSL_CHKERR1(endptr); // GCOV_EXCL_STOP // clean up if necessary @@ -361,8 +361,8 @@ int mock_bpa_eidpat_item_from_text(bsl_mock_eidpat_item_t *item, const char *tex bool mock_bpa_eidpat_item_match(const bsl_mock_eidpat_item_t *item, const bsl_mock_eid_t *eid) { // GCOV_EXCL_START - CHKERR1(item); - CHKERR1(eid); + BSL_CHKERR1(item); + BSL_CHKERR1(eid); // GCOV_EXCL_STOP if (item->scheme != eid->scheme) @@ -386,7 +386,7 @@ bool mock_bpa_eidpat_item_match(const bsl_mock_eidpat_item_t *item, const bsl_mo int mock_bpa_eidpat_init(BSL_HostEIDPattern_t *pat, void *user_data _U_) { - CHKERR1(pat); // GCOV_EXCL_LINE + BSL_CHKERR1(pat); // GCOV_EXCL_LINE memset(pat, 0, sizeof(BSL_HostEIDPattern_t)); pat->handle = BSL_MALLOC(sizeof(bsl_mock_eidpat_t)); @@ -404,7 +404,7 @@ int mock_bpa_eidpat_init(BSL_HostEIDPattern_t *pat, void *user_data _U_) static void bsl_mock_eidpat_deinit(bsl_mock_eidpat_t *pat) { - CHKVOID(pat); // GCOV_EXCL_LINE + BSL_CHKVOID(pat); // GCOV_EXCL_LINE bsl_mock_eidpat_item_list_clear(pat->items); memset(pat, 0, sizeof(bsl_mock_eidpat_t)); @@ -412,7 +412,7 @@ static void bsl_mock_eidpat_deinit(bsl_mock_eidpat_t *pat) void mock_bpa_eidpat_deinit(BSL_HostEIDPattern_t *pat, void *user_data _U_) { - CHKVOID(pat); + BSL_CHKVOID(pat); if (pat->handle) { bsl_mock_eidpat_deinit(pat->handle); @@ -424,10 +424,10 @@ void mock_bpa_eidpat_deinit(BSL_HostEIDPattern_t *pat, void *user_data _U_) int mock_bpa_eidpat_from_text(BSL_HostEIDPattern_t *pat, const char *text, void *user_data _U_) { // GCOV_EXCL_START - CHKERR1(pat); - CHKERR1(text); + BSL_CHKERR1(pat); + BSL_CHKERR1(text); bsl_mock_eidpat_t *obj = pat->handle; - CHKERR1(obj); + BSL_CHKERR1(obj); // GCOV_EXCL_STOP // clean up if necessary @@ -475,10 +475,10 @@ int mock_bpa_eidpat_from_text(BSL_HostEIDPattern_t *pat, const char *text, void bool mock_bpa_eidpat_match(const BSL_HostEIDPattern_t *pat, const BSL_HostEID_t *eid, void *user_data _U_) { // GCOV_EXCL_START - CHKERR1(pat); - CHKERR1(pat->handle); - CHKERR1(eid); - CHKERR1(eid->handle); + BSL_CHKERR1(pat); + BSL_CHKERR1(pat->handle); + BSL_CHKERR1(eid); + BSL_CHKERR1(eid->handle); // GCOV_EXCL_STOP bsl_mock_eidpat_t *patobj = (bsl_mock_eidpat_t *)pat->handle; diff --git a/src/mock_bpa/encode.c b/src/mock_bpa/encode.c index 5a1c77e..20d838b 100644 --- a/src/mock_bpa/encode.c +++ b/src/mock_bpa/encode.c @@ -35,7 +35,7 @@ int bsl_mock_encode_eid(const BSL_HostEID_t *eid, BSL_Data_t *encoded_bytes) bsl_mock_eid_t *obj = (bsl_mock_eid_t *)eid->handle; // GCOV_EXCL_START - CHKERR1(obj); + BSL_CHKERR1(obj); // GCOV_EXCL_STOP QCBOREncodeContext enc; diff --git a/src/mock_bpa/text_util.c b/src/mock_bpa/text_util.c index 632cc66..cb9f816 100644 --- a/src/mock_bpa/text_util.c +++ b/src/mock_bpa/text_util.c @@ -67,8 +67,8 @@ static const char *unreserved = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstu int mock_bpa_uri_percent_encode(m_string_t out, const m_string_t in, const char *safe) { - CHKERR1(out); - CHKERR1(in); + BSL_CHKERR1(out); + BSL_CHKERR1(in); const size_t in_len = m_string_size(in); const char *curs = m_string_get_cstr(in); @@ -113,8 +113,8 @@ int mock_bpa_uri_percent_encode(m_string_t out, const m_string_t in, const char int mock_bpa_uri_percent_decode(m_string_t out, const m_string_t in) { - CHKERR1(out); - CHKERR1(in); + BSL_CHKERR1(out); + BSL_CHKERR1(in); const size_t in_len = m_string_size(in); const char *curs = m_string_get_cstr(in); @@ -158,8 +158,8 @@ int mock_bpa_uri_percent_decode(m_string_t out, const m_string_t in) int mock_bpa_slash_escape(m_string_t out, const m_string_t in, const char quote) { - CHKERR1(out); - CHKERR1(in); + BSL_CHKERR1(out); + BSL_CHKERR1(in); // unicode iterator m_string_it_t it; @@ -214,8 +214,8 @@ int mock_bpa_slash_escape(m_string_t out, const m_string_t in, const char quote) int mock_bpa_slash_unescape(m_string_t out, const m_string_t in) { - CHKERR1(out); - CHKERR1(in); + BSL_CHKERR1(out); + BSL_CHKERR1(in); const size_t in_len = m_string_size(in); if (in_len == 0) @@ -369,7 +369,7 @@ void mock_bpa_strip_space(m_string_t out, const char *in, size_t in_len) void mock_bpa_string_tolower(m_string_t out) { - CHKVOID(out); + BSL_CHKVOID(out); size_t len = m_string_size(out); for (size_t i = 0; i < len; i++) { @@ -379,7 +379,7 @@ void mock_bpa_string_tolower(m_string_t out) void mock_bpa_string_toupper(m_string_t out) { - CHKVOID(out); + BSL_CHKVOID(out); size_t len = m_string_size(out); for (size_t i = 0; i < len; i++) { @@ -436,8 +436,8 @@ static int base16_decode_char(uint8_t chr) int mock_bpa_base16_decode(m_bstring_t out, const m_string_t in) { - CHKERR1(out); - CHKERR1(in); + BSL_CHKERR1(out); + BSL_CHKERR1(in); const size_t in_len = m_string_size(in); if (in_len % 2 != 0) @@ -588,8 +588,8 @@ static int base64_decode_char(uint8_t chr) int mock_bpa_base64_decode(m_bstring_t out, const m_string_t in) { - CHKERR1(out); - CHKERR1(in); + BSL_CHKERR1(out); + BSL_CHKERR1(in); size_t in_len = m_string_size(in); const char *curs = m_string_get_cstr(in); diff --git a/test/bsl_test_utils.c b/test/bsl_test_utils.c index 73fa69b..f246e27 100644 --- a/test/bsl_test_utils.c +++ b/test/bsl_test_utils.c @@ -396,8 +396,8 @@ static int BSL_TestUtils_DecodeBase16_char(uint8_t chr) int BSL_TestUtils_DecodeBase16(BSL_Data_t *out, const string_t in) { - CHKERR1(out); - CHKERR1(in); + BSL_CHKERR1(out); + BSL_CHKERR1(in); const size_t in_len = string_size(in); if (in_len % 2 != 0)