Skip to content

Commit 8401d38

Browse files
bradleysmith23actions-userSkptak
authored
MISRA fixes (#153)
* MISRA fixes * Uncrustify: triggered by comment. * Update doxygen comments * Formatting fixes * Uncrustify: triggered by comment. * Run github actions. * set coreJSON_ASSERT_DEFINED to 0 * Update loop_invariants.patch * Update assert definition * Uncrustify: triggered by comment. * Run Github Actions --------- Co-authored-by: GitHub Action <[email protected]> Co-authored-by: Soren Ptak <[email protected]>
1 parent dc1ab91 commit 8401d38

File tree

3 files changed

+56
-47
lines changed

3 files changed

+56
-47
lines changed

loop_invariants.patch

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ index 901b2e1..8bdd89c 100644
2525
* @brief Advance buffer index beyond whitespace.
2626
*
2727
@@ -78,6 +93,9 @@ static void skipSpace( const char * buf,
28-
assert( ( buf != NULL ) && ( start != NULL ) && ( max > 0U ) );
28+
coreJSON_ASSERT( ( buf != NULL ) && ( start != NULL ) && ( max > 0U ) );
2929

3030
for( i = *start; i < max; i++ )
3131
+ assigns( i )
@@ -86,7 +86,7 @@ index 901b2e1..8bdd89c 100644
8686
if( buf[ i ] == '"' )
8787
{
8888
@@ -580,6 +621,9 @@ static bool strnEq( const char * a,
89-
assert( ( a != NULL ) && ( b != NULL ) );
89+
coreJSON_ASSERT( ( a != NULL ) && ( b != NULL ) );
9090

9191
for( i = 0; i < n; i++ )
9292
+ assigns( i )
@@ -183,7 +183,7 @@ index 901b2e1..8bdd89c 100644
183183
i++;
184184
}
185185
@@ -1541,6 +1616,17 @@ static JSONStatus_t multiSearch( const char * buf,
186-
assert( ( max > 0U ) && ( queryLength > 0U ) );
186+
coreJSON_ASSERT( ( max > 0U ) && ( queryLength > 0U ) );
187187

188188
while( i < queryLength )
189189
+ assigns( i, start, queryStart, value, length )

source/core_json.c

Lines changed: 43 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
* @brief The source file that implements the user-facing functions in core_json.h.
2828
*/
2929

30-
#include <assert.h>
3130
#include <limits.h>
3231
#include <stddef.h>
3332
#include <stdint.h>
@@ -75,7 +74,7 @@ static void skipSpace( const char * buf,
7574
{
7675
size_t i = 0U;
7776

78-
assert( ( buf != NULL ) && ( start != NULL ) && ( max > 0U ) );
77+
coreJSON_ASSERT( ( buf != NULL ) && ( start != NULL ) && ( max > 0U ) );
7978

8079
for( i = *start; i < max; i++ )
8180
{
@@ -133,7 +132,7 @@ static bool shortestUTF8( size_t length,
133132
bool ret = false;
134133
uint32_t min = 0U, max = 0U;
135134

136-
assert( ( length >= 2U ) && ( length <= 4U ) );
135+
coreJSON_ASSERT( ( length >= 2U ) && ( length <= 4U ) );
137136

138137
switch( length )
139138
{
@@ -192,13 +191,13 @@ static bool skipUTF8MultiByte( const char * buf,
192191
bool ret = false;
193192
size_t i = 0U, bitCount = 0U, j = 0U;
194193
uint32_t value = 0U;
195-
char_ c = { 0 };
194+
char_ c;
196195

197-
assert( ( buf != NULL ) && ( start != NULL ) && ( max > 0U ) );
196+
coreJSON_ASSERT( ( buf != NULL ) && ( start != NULL ) && ( max > 0U ) );
198197

199198
i = *start;
200-
assert( i < max );
201-
assert( !isascii_( buf[ i ] ) );
199+
coreJSON_ASSERT( i < max );
200+
coreJSON_ASSERT( !isascii_( buf[ i ] ) );
202201

203202
c.c = buf[ i ];
204203

@@ -255,7 +254,7 @@ static bool skipUTF8( const char * buf,
255254
{
256255
bool ret = false;
257256

258-
assert( ( buf != NULL ) && ( start != NULL ) && ( max > 0U ) );
257+
coreJSON_ASSERT( ( buf != NULL ) && ( start != NULL ) && ( max > 0U ) );
259258

260259
if( *start < max )
261260
{
@@ -283,7 +282,7 @@ static bool skipUTF8( const char * buf,
283282
#define NOT_A_HEX_CHAR ( 0x10U )
284283
static uint8_t hexToInt( char c )
285284
{
286-
char_ n = { 0 };
285+
char_ n;
287286

288287
n.c = c;
289288

@@ -332,8 +331,8 @@ static bool skipOneHexEscape( const char * buf,
332331
size_t i = 0U, end = 0U;
333332
uint16_t value = 0U;
334333

335-
assert( ( buf != NULL ) && ( start != NULL ) && ( max > 0U ) );
336-
assert( outValue != NULL );
334+
coreJSON_ASSERT( ( buf != NULL ) && ( start != NULL ) && ( max > 0U ) );
335+
coreJSON_ASSERT( outValue != NULL );
337336

338337
i = *start;
339338
#define HEX_ESCAPE_LENGTH ( 6U ) /* e.g., \u1234 */
@@ -395,7 +394,7 @@ static bool skipHexEscape( const char * buf,
395394
size_t i = 0U;
396395
uint16_t value = 0U;
397396

398-
assert( ( buf != NULL ) && ( start != NULL ) && ( max > 0U ) );
397+
coreJSON_ASSERT( ( buf != NULL ) && ( start != NULL ) && ( max > 0U ) );
399398

400399
i = *start;
401400

@@ -446,7 +445,7 @@ static bool skipEscape( const char * buf,
446445
bool ret = false;
447446
size_t i = 0U;
448447

449-
assert( ( buf != NULL ) && ( start != NULL ) && ( max > 0U ) );
448+
coreJSON_ASSERT( ( buf != NULL ) && ( start != NULL ) && ( max > 0U ) );
450449

451450
i = *start;
452451

@@ -513,7 +512,7 @@ static bool skipString( const char * buf,
513512
bool ret = false;
514513
size_t i = 0;
515514

516-
assert( ( buf != NULL ) && ( start != NULL ) && ( max > 0U ) );
515+
coreJSON_ASSERT( ( buf != NULL ) && ( start != NULL ) && ( max > 0U ) );
517516

518517
i = *start;
519518

@@ -577,7 +576,7 @@ static bool strnEq( const char * a,
577576
{
578577
size_t i = 0U;
579578

580-
assert( ( a != NULL ) && ( b != NULL ) );
579+
coreJSON_ASSERT( ( a != NULL ) && ( b != NULL ) );
581580

582581
for( i = 0; i < n; i++ )
583582
{
@@ -610,8 +609,8 @@ static bool skipLiteral( const char * buf,
610609
{
611610
bool ret = false;
612611

613-
assert( ( buf != NULL ) && ( start != NULL ) && ( max > 0U ) );
614-
assert( literal != NULL );
612+
coreJSON_ASSERT( ( buf != NULL ) && ( start != NULL ) && ( max > 0U ) );
613+
coreJSON_ASSERT( literal != NULL );
615614

616615
if( ( *start < max ) && ( length <= ( max - *start ) ) )
617616
{
@@ -690,7 +689,7 @@ static bool skipDigits( const char * buf,
690689
size_t i = 0U, saveStart = 0U;
691690
int32_t value = 0;
692691

693-
assert( ( buf != NULL ) && ( start != NULL ) && ( max > 0U ) );
692+
coreJSON_ASSERT( ( buf != NULL ) && ( start != NULL ) && ( max > 0U ) );
694693

695694
saveStart = *start;
696695

@@ -743,7 +742,7 @@ static void skipDecimals( const char * buf,
743742
{
744743
size_t i = 0U;
745744

746-
assert( ( buf != NULL ) && ( start != NULL ) && ( max > 0U ) );
745+
coreJSON_ASSERT( ( buf != NULL ) && ( start != NULL ) && ( max > 0U ) );
747746

748747
i = *start;
749748

@@ -771,7 +770,7 @@ static void skipExponent( const char * buf,
771770
{
772771
size_t i = 0U;
773772

774-
assert( ( buf != NULL ) && ( start != NULL ) && ( max > 0U ) );
773+
coreJSON_ASSERT( ( buf != NULL ) && ( start != NULL ) && ( max > 0U ) );
775774

776775
i = *start;
777776

@@ -808,7 +807,7 @@ static bool skipNumber( const char * buf,
808807
bool ret = false;
809808
size_t i = 0U;
810809

811-
assert( ( buf != NULL ) && ( start != NULL ) && ( max > 0U ) );
810+
coreJSON_ASSERT( ( buf != NULL ) && ( start != NULL ) && ( max > 0U ) );
812811

813812
i = *start;
814813

@@ -904,7 +903,7 @@ static bool skipSpaceAndComma( const char * buf,
904903
bool ret = false;
905904
size_t i = 0U;
906905

907-
assert( ( buf != NULL ) && ( start != NULL ) && ( max > 0U ) );
906+
coreJSON_ASSERT( ( buf != NULL ) && ( start != NULL ) && ( max > 0U ) );
908907

909908
skipSpace( buf, start, max );
910909
i = *start;
@@ -939,7 +938,7 @@ static void skipArrayScalars( const char * buf,
939938
{
940939
size_t i = 0U;
941940

942-
assert( ( buf != NULL ) && ( start != NULL ) && ( max > 0U ) );
941+
coreJSON_ASSERT( ( buf != NULL ) && ( start != NULL ) && ( max > 0U ) );
943942

944943
i = *start;
945944

@@ -981,7 +980,7 @@ static void skipObjectScalars( const char * buf,
981980
size_t i = 0U;
982981
bool comma = false;
983982

984-
assert( ( buf != NULL ) && ( start != NULL ) && ( max > 0U ) );
983+
coreJSON_ASSERT( ( buf != NULL ) && ( start != NULL ) && ( max > 0U ) );
985984

986985
i = *start;
987986

@@ -1036,7 +1035,7 @@ static void skipScalars( const char * buf,
10361035
size_t max,
10371036
char mode )
10381037
{
1039-
assert( isOpenBracket_( mode ) );
1038+
coreJSON_ASSERT( isOpenBracket_( mode ) );
10401039

10411040
skipSpace( buf, start, max );
10421041

@@ -1077,7 +1076,7 @@ static JSONStatus_t skipCollection( const char * buf,
10771076
int16_t depth = -1;
10781077
size_t i = 0U;
10791078

1080-
assert( ( buf != NULL ) && ( start != NULL ) && ( max > 0U ) );
1079+
coreJSON_ASSERT( ( buf != NULL ) && ( start != NULL ) && ( max > 0U ) );
10811080

10821081
i = *start;
10831082

@@ -1222,8 +1221,8 @@ static bool nextValue( const char * buf,
12221221
bool ret = true;
12231222
size_t i = 0U, valueStart = 0U;
12241223

1225-
assert( ( buf != NULL ) && ( start != NULL ) && ( max > 0U ) );
1226-
assert( ( value != NULL ) && ( valueLength != NULL ) );
1224+
coreJSON_ASSERT( ( buf != NULL ) && ( start != NULL ) && ( max > 0U ) );
1225+
coreJSON_ASSERT( ( value != NULL ) && ( valueLength != NULL ) );
12271226

12281227
i = *start;
12291228
valueStart = i;
@@ -1279,9 +1278,9 @@ static bool nextKeyValuePair( const char * buf,
12791278
bool ret = true;
12801279
size_t i = 0U, keyStart = 0U;
12811280

1282-
assert( ( buf != NULL ) && ( start != NULL ) && ( max > 0U ) );
1283-
assert( ( key != NULL ) && ( keyLength != NULL ) );
1284-
assert( ( value != NULL ) && ( valueLength != NULL ) );
1281+
coreJSON_ASSERT( ( buf != NULL ) && ( start != NULL ) && ( max > 0U ) );
1282+
coreJSON_ASSERT( ( key != NULL ) && ( keyLength != NULL ) );
1283+
coreJSON_ASSERT( ( value != NULL ) && ( valueLength != NULL ) );
12851284

12861285
i = *start;
12871286
keyStart = i;
@@ -1352,8 +1351,8 @@ static bool objectSearch( const char * buf,
13521351

13531352
size_t i = 0U, key = 0U, keyLength = 0U, value = 0U, valueLength = 0U;
13541353

1355-
assert( ( buf != NULL ) && ( query != NULL ) );
1356-
assert( ( outValue != NULL ) && ( outValueLength != NULL ) );
1354+
coreJSON_ASSERT( ( buf != NULL ) && ( query != NULL ) );
1355+
coreJSON_ASSERT( ( outValue != NULL ) && ( outValueLength != NULL ) );
13571356

13581357
skipSpace( buf, &i, max );
13591358

@@ -1419,8 +1418,8 @@ static bool arraySearch( const char * buf,
14191418
size_t i = 0U, value = 0U, valueLength = 0U;
14201419
uint32_t currentIndex = 0U;
14211420

1422-
assert( buf != NULL );
1423-
assert( ( outValue != NULL ) && ( outValueLength != NULL ) );
1421+
coreJSON_ASSERT( buf != NULL );
1422+
coreJSON_ASSERT( ( outValue != NULL ) && ( outValueLength != NULL ) );
14241423

14251424
skipSpace( buf, &i, max );
14261425

@@ -1487,8 +1486,8 @@ static bool skipQueryPart( const char * buf,
14871486
bool ret = false;
14881487
size_t i = 0U;
14891488

1490-
assert( ( buf != NULL ) && ( start != NULL ) && ( outLength != NULL ) );
1491-
assert( max > 0U );
1489+
coreJSON_ASSERT( ( buf != NULL ) && ( start != NULL ) && ( outLength != NULL ) );
1490+
coreJSON_ASSERT( max > 0U );
14921491

14931492
i = *start;
14941493

@@ -1536,9 +1535,9 @@ static JSONStatus_t multiSearch( const char * buf,
15361535
JSONStatus_t ret = JSONSuccess;
15371536
size_t i = 0U, start = 0U, queryStart = 0U, value = 0U, length = max;
15381537

1539-
assert( ( buf != NULL ) && ( query != NULL ) );
1540-
assert( ( outValue != NULL ) && ( outValueLength != NULL ) );
1541-
assert( ( max > 0U ) && ( queryLength > 0U ) );
1538+
coreJSON_ASSERT( ( buf != NULL ) && ( query != NULL ) );
1539+
coreJSON_ASSERT( ( outValue != NULL ) && ( outValueLength != NULL ) );
1540+
coreJSON_ASSERT( ( max > 0U ) && ( queryLength > 0U ) );
15421541

15431542
while( i < queryLength )
15441543
{
@@ -1747,10 +1746,10 @@ static JSONStatus_t iterate( const char * buf,
17471746
JSONStatus_t ret = JSONNotFound;
17481747
bool found = false;
17491748

1750-
assert( ( buf != NULL ) && ( max > 0U ) );
1751-
assert( ( start != NULL ) && ( next != NULL ) );
1752-
assert( ( outKey != NULL ) && ( outKeyLength != NULL ) );
1753-
assert( ( outValue != NULL ) && ( outValueLength != NULL ) );
1749+
coreJSON_ASSERT( ( buf != NULL ) && ( max > 0U ) );
1750+
coreJSON_ASSERT( ( start != NULL ) && ( next != NULL ) );
1751+
coreJSON_ASSERT( ( outKey != NULL ) && ( outKeyLength != NULL ) );
1752+
coreJSON_ASSERT( ( outValue != NULL ) && ( outValueLength != NULL ) );
17541753

17551754
if( *start < max )
17561755
{

source/include/core_json.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#ifndef CORE_JSON_H_
3131
#define CORE_JSON_H_
3232

33+
#include <assert.h>
3334
#include <stdbool.h>
3435
#include <stddef.h>
3536

@@ -39,6 +40,15 @@
3940
#endif
4041
/* *INDENT-ON* */
4142

43+
/**
44+
* @brief By default, has the stand behavior of assert() for
45+
* parameter checking. To swap out the assert(), define this
46+
* macro with the desired behavior. */
47+
#ifndef coreJSON_ASSERT
48+
#define coreJSON_ASSERT( expr ) assert( expr )
49+
#endif
50+
51+
4252
/**
4353
* @ingroup json_enum_types
4454
* @brief Return codes from coreJSON library functions.

0 commit comments

Comments
 (0)