Skip to content

Commit

Permalink
Fix short-circuiting operations with side-effects
Browse files Browse the repository at this point in the history
MISRA forbids having expressions with side effects on the right side of
an && or || operator.
  • Loading branch information
archigup committed Aug 2, 2023
1 parent 8d216b5 commit dff33ff
Showing 1 changed file with 34 additions and 8 deletions.
42 changes: 34 additions & 8 deletions source/core_json.c
Original file line number Diff line number Diff line change
Expand Up @@ -640,15 +640,27 @@ static bool skipAnyLiteral( const char * buf,
size_t * start,
size_t max )
{
bool ret = false;
bool ret;

#define skipLit_( x ) \
( skipLiteral( buf, start, max, ( x ), ( sizeof( x ) - 1UL ) ) == true )

if( skipLit_( "true" ) || skipLit_( "false" ) || skipLit_( "null" ) )
if( skipLit_( "true" ) )
{
ret = true;
}
else if (skipLit_( "false" ) )
{
ret = true;
}
else if (skipLit_( "null" ) )
{
ret = true;
}
else
{
ret = false;
}

return ret;
}
Expand Down Expand Up @@ -849,14 +861,24 @@ static bool skipAnyScalar( const char * buf,
size_t * start,
size_t max )
{
bool ret = false;
bool ret;

if( ( skipString( buf, start, max ) == true ) ||
( skipAnyLiteral( buf, start, max ) == true ) ||
( skipNumber( buf, start, max ) == true ) )
if( skipString( buf, start, max ) == true )
{
ret = true;
}
else if( skipAnyLiteral( buf, start, max ) == true )
{
ret = true;
}
else if( skipNumber( buf, start, max ) == true )
{
ret = true;
}
else
{
ret = false;
}

return ret;
}
Expand Down Expand Up @@ -1204,8 +1226,12 @@ static bool nextValue( const char * buf,
i = *start;
valueStart = i;

if( ( skipAnyScalar( buf, &i, max ) == true ) ||
( skipCollection( buf, &i, max ) == JSONSuccess ) )
if( skipAnyScalar( buf, &i, max ) == true )
{
*value = valueStart;
*valueLength = i - valueStart;
}
else if( skipCollection( buf, &i, max ) == JSONSuccess )
{
*value = valueStart;
*valueLength = i - valueStart;
Expand Down

0 comments on commit dff33ff

Please sign in to comment.