Skip to content

Commit 753ddcd

Browse files
Rename CHK* to BSL_CHK* (#138)
* Rename CHK* to BSL_CHK* * Apply format * format on ubuntu 24 --------- Co-authored-by: Brian Sipos <brian.sipos@jhuapl.edu>
1 parent 33ee4f2 commit 753ddcd

10 files changed

Lines changed: 69 additions & 69 deletions

File tree

docs/api/10-bsl-developers.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,11 @@ When heap memory is needed at BSL runtime, the following macros are used and hav
226226
To help with the error reporting conventions above, the following macros can be used to simplify function precondition checking.
227227
The precondition checks (on function parameters or on any other state generally) should be the first thing inside the function definition.
228228

229-
- [CHKRET(cond, val)](@ref CHKRET) for general error values
230-
- [CHKNULL(cond)](@ref CHKNULL) when the function has a pointer return type
231-
- [CHKERR1(cond)](@ref CHKERR1) when the function has an `int` return type
232-
- [CHKVOID(cond)](@ref CHKVOID) when the function has an `void` return type
233-
- [CHKFALSE(cond)](@ref CHKFALSE) when the function has an `bool` return type
229+
- [BSL_CHKRET(cond, val)](@ref BSL_CHKRET) for general error values
230+
- [BSL_CHKNULL(cond)](@ref BSL_CHKNULL) when the function has a pointer return type
231+
- [BSL_CHKERR1(cond)](@ref BSL_CHKERR1) when the function has an `int` return type
232+
- [BSL_CHKVOID(cond)](@ref BSL_CHKVOID) when the function has an `void` return type
233+
- [BSL_CHKFALSE(cond)](@ref BSL_CHKFALSE) when the function has an `bool` return type
234234

235235
# Enumerations
236236

src/BPSecLib_Private.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,25 +129,25 @@ typedef enum
129129
* @param val The return value if the check fails.
130130
* @deprecated
131131
*/
132-
#define CHKRET(cond, val) \
133-
if (!LIKELY(cond)) \
134-
{ \
135-
return val; \
132+
#define BSL_CHKRET(cond, val) \
133+
if (!LIKELY(cond)) \
134+
{ \
135+
return val; \
136136
}
137137
/// Return from void functions if condition fails.
138-
#define CHKVOID(cond) CHKRET(cond, )
138+
#define BSL_CHKVOID(cond) BSL_CHKRET(cond, )
139139
/// Return a null pointer if condition fails.
140-
#define CHKNULL(cond) CHKRET(cond, NULL)
140+
#define BSL_CHKNULL(cond) BSL_CHKRET(cond, NULL)
141141
/// Return false if condition fails.
142-
#define CHKFALSE(cond) CHKRET(cond, false)
142+
#define BSL_CHKFALSE(cond) BSL_CHKRET(cond, false)
143143
/// Return the error value 1 if condition fails.
144-
#define CHKERR1(cond) CHKRET(cond, 1)
144+
#define BSL_CHKERR1(cond) BSL_CHKRET(cond, 1)
145145
/** Check a value for non-zero and return that value.
146146
* @warning The parameter is evaluated twice so should be a simple variable.
147147
*
148148
* @param value The value to check and conditionally return.
149149
*/
150-
#define CHKERRVAL(value) CHKRET(!(value), (value))
150+
#define BSL_CHKERRVAL(value) BSL_CHKRET(!(value), (value))
151151

152152
/** @brief Codes indicating the fate of a block if a security operation over it fails
153153
*

src/backend/LoggingStderr.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,8 @@ void BSL_closelog(void)
261261

262262
int BSL_LogGetSeverity(int *severity, const char *name)
263263
{
264-
CHKERR1(severity)
265-
CHKERR1(name)
264+
BSL_CHKERR1(severity);
265+
BSL_CHKERR1(name);
266266

267267
for (size_t ix = 0; ix < sizeof(sev_names) / sizeof(const char *); ++ix)
268268
{

src/mock_bpa/ctr.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
void mock_bpa_ctr_init(mock_bpa_ctr_t *ctr)
3030
{
31-
CHKVOID(ctr);
31+
BSL_CHKVOID(ctr);
3232
memset(ctr, 0, sizeof(*ctr));
3333

3434
BSL_Data_Init(&(ctr->encoded));
@@ -41,8 +41,8 @@ void mock_bpa_ctr_init(mock_bpa_ctr_t *ctr)
4141

4242
void mock_bpa_ctr_init_move(mock_bpa_ctr_t *ctr, mock_bpa_ctr_t *src)
4343
{
44-
CHKVOID(ctr);
45-
CHKVOID(src);
44+
BSL_CHKVOID(ctr);
45+
BSL_CHKVOID(src);
4646
BSL_Data_InitMove(&(ctr->encoded), &(src->encoded));
4747

4848
ctr->bundle = src->bundle;
@@ -54,7 +54,7 @@ void mock_bpa_ctr_init_move(mock_bpa_ctr_t *ctr, mock_bpa_ctr_t *src)
5454

5555
void mock_bpa_ctr_deinit(mock_bpa_ctr_t *ctr)
5656
{
57-
CHKVOID(ctr);
57+
BSL_CHKVOID(ctr);
5858
BSL_Data_Deinit(&(ctr->encoded));
5959

6060
if (ctr->bundle)
@@ -66,7 +66,7 @@ void mock_bpa_ctr_deinit(mock_bpa_ctr_t *ctr)
6666

6767
int mock_bpa_decode(mock_bpa_ctr_t *ctr)
6868
{
69-
CHKERR1(ctr);
69+
BSL_CHKERR1(ctr);
7070
MockBPA_Bundle_t *bundle = ctr->bundle_ref.data;
7171

7272
if (ctr->bundle_ref.data)
@@ -110,9 +110,9 @@ M_ALGO_DEF(MockBPA_BlockList, M_DEQUE_OPLIST(MockBPA_BlockList, M_OPEXTEND(M_POD
110110

111111
int mock_bpa_encode(mock_bpa_ctr_t *ctr)
112112
{
113-
CHKERR1(ctr);
113+
BSL_CHKERR1(ctr);
114114
MockBPA_Bundle_t *bundle = ctr->bundle_ref.data;
115-
CHKERR1(bundle);
115+
BSL_CHKERR1(bundle);
116116

117117
// TODO this is not really defined by BPSec or BPv7
118118
MockBPA_BlockList_sort(bundle->blocks);

src/mock_bpa/decode.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ int bsl_mock_decode_eid_from_ctx(QCBORDecodeContext *dec, BSL_HostEID_t *eid)
150150
int bsl_mock_decode_primary(QCBORDecodeContext *dec, MockBPA_PrimaryBlock_t *blk)
151151
{
152152
// GCOV_EXCL_START
153-
CHKERR1(dec);
154-
CHKERR1(blk);
153+
BSL_CHKERR1(dec);
154+
BSL_CHKERR1(blk);
155155
// GCOV_EXCL_STOP
156156

157157
const size_t begin = QCBORDecode_Tell(dec);
@@ -236,8 +236,8 @@ int bsl_mock_decode_primary(QCBORDecodeContext *dec, MockBPA_PrimaryBlock_t *blk
236236
int bsl_mock_decode_canonical(QCBORDecodeContext *dec, MockBPA_CanonicalBlock_t *blk)
237237
{
238238
// GCOV_EXCL_START
239-
CHKERR1(dec);
240-
CHKERR1(blk);
239+
BSL_CHKERR1(dec);
240+
BSL_CHKERR1(blk);
241241
// GCOV_EXCL_STOP
242242

243243
const size_t begin = QCBORDecode_Tell(dec);
@@ -299,8 +299,8 @@ int bsl_mock_decode_canonical(QCBORDecodeContext *dec, MockBPA_CanonicalBlock_t
299299
int bsl_mock_decode_bundle(QCBORDecodeContext *dec, MockBPA_Bundle_t *bundle)
300300
{
301301
// GCOV_EXCL_START
302-
CHKERR1(dec);
303-
CHKERR1(bundle);
302+
BSL_CHKERR1(dec);
303+
BSL_CHKERR1(bundle);
304304
// GCOV_EXCL_STOP
305305

306306
QCBORItem decitem;

src/mock_bpa/eid.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@
3535

3636
void bsl_mock_eid_init(bsl_mock_eid_t *eid)
3737
{
38-
CHKVOID(eid);
38+
BSL_CHKVOID(eid);
3939
memset(eid, 0, sizeof(bsl_mock_eid_t));
4040
}
4141

4242
void bsl_mock_eid_deinit(bsl_mock_eid_t *eid)
4343
{
44-
CHKVOID(eid);
44+
BSL_CHKVOID(eid);
4545
switch (eid->scheme)
4646
{
4747
case BSL_MOCK_EID_IPN:
@@ -55,7 +55,7 @@ void bsl_mock_eid_deinit(bsl_mock_eid_t *eid)
5555

5656
int MockBPA_EID_Init(void *user_data _U_, BSL_HostEID_t *eid)
5757
{
58-
CHKERR1(eid);
58+
BSL_CHKERR1(eid);
5959
memset(eid, 0, sizeof(BSL_HostEID_t));
6060
eid->handle = BSL_MALLOC(sizeof(bsl_mock_eid_t));
6161
if (!(eid->handle))
@@ -68,7 +68,7 @@ int MockBPA_EID_Init(void *user_data _U_, BSL_HostEID_t *eid)
6868

6969
void MockBPA_EID_Deinit(void *user_data _U_, BSL_HostEID_t *eid)
7070
{
71-
CHKVOID(eid);
71+
BSL_CHKVOID(eid);
7272
if (eid->handle)
7373
{
7474
bsl_mock_eid_deinit(eid->handle);
@@ -79,8 +79,8 @@ void MockBPA_EID_Deinit(void *user_data _U_, BSL_HostEID_t *eid)
7979

8080
int mock_bpa_eid_from_text(BSL_HostEID_t *eid, const char *text, void *user_data _U_)
8181
{
82-
CHKERR1(eid);
83-
CHKERR1(text);
82+
BSL_CHKERR1(eid);
83+
BSL_CHKERR1(text);
8484

8585
// any spaces are invalid URI
8686
// agrees with isspace()
@@ -174,8 +174,8 @@ int mock_bpa_eid_from_text(BSL_HostEID_t *eid, const char *text, void *user_data
174174

175175
// int mock_bpa_eid_to_text(string_t out, const BSL_HostEID_t *eid, void *user_data _U_)
176176
// {
177-
// CHKERR1(eid);
178-
// CHKERR1(eid->handle);
177+
// BSL_CHKERR1(eid);
178+
// BSL_CHKERR1(eid->handle);
179179
// bsl_mock_eid_t *obj = (bsl_mock_eid_t *)eid->handle;
180180

181181
// switch (obj->scheme)

src/mock_bpa/eidpat.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -283,9 +283,9 @@ void bsl_mock_eidpat_item_deinit(bsl_mock_eidpat_item_t *obj)
283283
int mock_bpa_eidpat_item_from_text(bsl_mock_eidpat_item_t *item, const char *text, const char **endptr)
284284
{
285285
// GCOV_EXCL_START
286-
CHKERR1(item);
287-
CHKERR1(text);
288-
CHKERR1(endptr);
286+
BSL_CHKERR1(item);
287+
BSL_CHKERR1(text);
288+
BSL_CHKERR1(endptr);
289289
// GCOV_EXCL_STOP
290290

291291
// clean up if necessary
@@ -361,8 +361,8 @@ int mock_bpa_eidpat_item_from_text(bsl_mock_eidpat_item_t *item, const char *tex
361361
bool mock_bpa_eidpat_item_match(const bsl_mock_eidpat_item_t *item, const bsl_mock_eid_t *eid)
362362
{
363363
// GCOV_EXCL_START
364-
CHKERR1(item);
365-
CHKERR1(eid);
364+
BSL_CHKERR1(item);
365+
BSL_CHKERR1(eid);
366366
// GCOV_EXCL_STOP
367367

368368
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
386386

387387
int mock_bpa_eidpat_init(BSL_HostEIDPattern_t *pat, void *user_data _U_)
388388
{
389-
CHKERR1(pat); // GCOV_EXCL_LINE
389+
BSL_CHKERR1(pat); // GCOV_EXCL_LINE
390390

391391
memset(pat, 0, sizeof(BSL_HostEIDPattern_t));
392392
pat->handle = BSL_MALLOC(sizeof(bsl_mock_eidpat_t));
@@ -404,15 +404,15 @@ int mock_bpa_eidpat_init(BSL_HostEIDPattern_t *pat, void *user_data _U_)
404404

405405
static void bsl_mock_eidpat_deinit(bsl_mock_eidpat_t *pat)
406406
{
407-
CHKVOID(pat); // GCOV_EXCL_LINE
407+
BSL_CHKVOID(pat); // GCOV_EXCL_LINE
408408

409409
bsl_mock_eidpat_item_list_clear(pat->items);
410410
memset(pat, 0, sizeof(bsl_mock_eidpat_t));
411411
}
412412

413413
void mock_bpa_eidpat_deinit(BSL_HostEIDPattern_t *pat, void *user_data _U_)
414414
{
415-
CHKVOID(pat);
415+
BSL_CHKVOID(pat);
416416
if (pat->handle)
417417
{
418418
bsl_mock_eidpat_deinit(pat->handle);
@@ -424,10 +424,10 @@ void mock_bpa_eidpat_deinit(BSL_HostEIDPattern_t *pat, void *user_data _U_)
424424
int mock_bpa_eidpat_from_text(BSL_HostEIDPattern_t *pat, const char *text, void *user_data _U_)
425425
{
426426
// GCOV_EXCL_START
427-
CHKERR1(pat);
428-
CHKERR1(text);
427+
BSL_CHKERR1(pat);
428+
BSL_CHKERR1(text);
429429
bsl_mock_eidpat_t *obj = pat->handle;
430-
CHKERR1(obj);
430+
BSL_CHKERR1(obj);
431431
// GCOV_EXCL_STOP
432432

433433
// clean up if necessary
@@ -475,10 +475,10 @@ int mock_bpa_eidpat_from_text(BSL_HostEIDPattern_t *pat, const char *text, void
475475
bool mock_bpa_eidpat_match(const BSL_HostEIDPattern_t *pat, const BSL_HostEID_t *eid, void *user_data _U_)
476476
{
477477
// GCOV_EXCL_START
478-
CHKERR1(pat);
479-
CHKERR1(pat->handle);
480-
CHKERR1(eid);
481-
CHKERR1(eid->handle);
478+
BSL_CHKERR1(pat);
479+
BSL_CHKERR1(pat->handle);
480+
BSL_CHKERR1(eid);
481+
BSL_CHKERR1(eid->handle);
482482
// GCOV_EXCL_STOP
483483

484484
bsl_mock_eidpat_t *patobj = (bsl_mock_eidpat_t *)pat->handle;

src/mock_bpa/encode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ int bsl_mock_encode_eid(const BSL_HostEID_t *eid, BSL_Data_t *encoded_bytes)
3535
bsl_mock_eid_t *obj = (bsl_mock_eid_t *)eid->handle;
3636

3737
// GCOV_EXCL_START
38-
CHKERR1(obj);
38+
BSL_CHKERR1(obj);
3939
// GCOV_EXCL_STOP
4040

4141
QCBOREncodeContext enc;

src/mock_bpa/text_util.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ static const char *unreserved = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstu
6767

6868
int mock_bpa_uri_percent_encode(m_string_t out, const m_string_t in, const char *safe)
6969
{
70-
CHKERR1(out);
71-
CHKERR1(in);
70+
BSL_CHKERR1(out);
71+
BSL_CHKERR1(in);
7272

7373
const size_t in_len = m_string_size(in);
7474
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
113113

114114
int mock_bpa_uri_percent_decode(m_string_t out, const m_string_t in)
115115
{
116-
CHKERR1(out);
117-
CHKERR1(in);
116+
BSL_CHKERR1(out);
117+
BSL_CHKERR1(in);
118118

119119
const size_t in_len = m_string_size(in);
120120
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)
158158

159159
int mock_bpa_slash_escape(m_string_t out, const m_string_t in, const char quote)
160160
{
161-
CHKERR1(out);
162-
CHKERR1(in);
161+
BSL_CHKERR1(out);
162+
BSL_CHKERR1(in);
163163

164164
// unicode iterator
165165
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)
214214

215215
int mock_bpa_slash_unescape(m_string_t out, const m_string_t in)
216216
{
217-
CHKERR1(out);
218-
CHKERR1(in);
217+
BSL_CHKERR1(out);
218+
BSL_CHKERR1(in);
219219

220220
const size_t in_len = m_string_size(in);
221221
if (in_len == 0)
@@ -369,7 +369,7 @@ void mock_bpa_strip_space(m_string_t out, const char *in, size_t in_len)
369369

370370
void mock_bpa_string_tolower(m_string_t out)
371371
{
372-
CHKVOID(out);
372+
BSL_CHKVOID(out);
373373
size_t len = m_string_size(out);
374374
for (size_t i = 0; i < len; i++)
375375
{
@@ -379,7 +379,7 @@ void mock_bpa_string_tolower(m_string_t out)
379379

380380
void mock_bpa_string_toupper(m_string_t out)
381381
{
382-
CHKVOID(out);
382+
BSL_CHKVOID(out);
383383
size_t len = m_string_size(out);
384384
for (size_t i = 0; i < len; i++)
385385
{
@@ -436,8 +436,8 @@ static int base16_decode_char(uint8_t chr)
436436

437437
int mock_bpa_base16_decode(m_bstring_t out, const m_string_t in)
438438
{
439-
CHKERR1(out);
440-
CHKERR1(in);
439+
BSL_CHKERR1(out);
440+
BSL_CHKERR1(in);
441441

442442
const size_t in_len = m_string_size(in);
443443
if (in_len % 2 != 0)
@@ -588,8 +588,8 @@ static int base64_decode_char(uint8_t chr)
588588

589589
int mock_bpa_base64_decode(m_bstring_t out, const m_string_t in)
590590
{
591-
CHKERR1(out);
592-
CHKERR1(in);
591+
BSL_CHKERR1(out);
592+
BSL_CHKERR1(in);
593593

594594
size_t in_len = m_string_size(in);
595595
const char *curs = m_string_get_cstr(in);

test/bsl_test_utils.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,8 +396,8 @@ static int BSL_TestUtils_DecodeBase16_char(uint8_t chr)
396396

397397
int BSL_TestUtils_DecodeBase16(BSL_Data_t *out, const string_t in)
398398
{
399-
CHKERR1(out);
400-
CHKERR1(in);
399+
BSL_CHKERR1(out);
400+
BSL_CHKERR1(in);
401401

402402
const size_t in_len = string_size(in);
403403
if (in_len % 2 != 0)

0 commit comments

Comments
 (0)