Skip to content

Commit 84f903f

Browse files
authored
Fix short-circuiting operations with side-effects (#148)
MISRA forbids having expressions with side effects on the right side of an && or || operator.
1 parent 8d216b5 commit 84f903f

File tree

1 file changed

+34
-8
lines changed

1 file changed

+34
-8
lines changed

source/core_json.c

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -640,15 +640,27 @@ static bool skipAnyLiteral( const char * buf,
640640
size_t * start,
641641
size_t max )
642642
{
643-
bool ret = false;
643+
bool ret;
644644

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

648-
if( skipLit_( "true" ) || skipLit_( "false" ) || skipLit_( "null" ) )
648+
if( skipLit_( "true" ) )
649+
{
650+
ret = true;
651+
}
652+
else if( skipLit_( "false" ) )
653+
{
654+
ret = true;
655+
}
656+
else if( skipLit_( "null" ) )
649657
{
650658
ret = true;
651659
}
660+
else
661+
{
662+
ret = false;
663+
}
652664

653665
return ret;
654666
}
@@ -849,14 +861,24 @@ static bool skipAnyScalar( const char * buf,
849861
size_t * start,
850862
size_t max )
851863
{
852-
bool ret = false;
864+
bool ret;
853865

854-
if( ( skipString( buf, start, max ) == true ) ||
855-
( skipAnyLiteral( buf, start, max ) == true ) ||
856-
( skipNumber( buf, start, max ) == true ) )
866+
if( skipString( buf, start, max ) == true )
867+
{
868+
ret = true;
869+
}
870+
else if( skipAnyLiteral( buf, start, max ) == true )
857871
{
858872
ret = true;
859873
}
874+
else if( skipNumber( buf, start, max ) == true )
875+
{
876+
ret = true;
877+
}
878+
else
879+
{
880+
ret = false;
881+
}
860882

861883
return ret;
862884
}
@@ -1204,8 +1226,12 @@ static bool nextValue( const char * buf,
12041226
i = *start;
12051227
valueStart = i;
12061228

1207-
if( ( skipAnyScalar( buf, &i, max ) == true ) ||
1208-
( skipCollection( buf, &i, max ) == JSONSuccess ) )
1229+
if( skipAnyScalar( buf, &i, max ) == true )
1230+
{
1231+
*value = valueStart;
1232+
*valueLength = i - valueStart;
1233+
}
1234+
else if( skipCollection( buf, &i, max ) == JSONSuccess )
12091235
{
12101236
*value = valueStart;
12111237
*valueLength = i - valueStart;

0 commit comments

Comments
 (0)