11diff --git a/source/core_json.c b/source/core_json.c
2- index d8694f0..761c44b 100644
2+ index a01c393..ad48f28 100644
33--- a/source/core_json.c
44+++ b/source/core_json.c
55@@ -63,6 +63,21 @@ typedef union
66 #define isCurlyOpen_( x ) ( ( x ) == '{' )
77 #define isCurlyClose_( x ) ( ( x ) == '}' )
8-
8+
99+ /**
1010+ * Renaming all loop-contract clauses from CBMC for readability.
1111+ * For more information about loop contracts in CBMC, see
@@ -26,7 +26,7 @@ index d8694f0..761c44b 100644
2626 *
2727@@ -79,6 +94,9 @@ static void skipSpace( const char * buf,
2828 coreJSON_ASSERT( ( buf != NULL ) && ( start != NULL ) && ( max > 0U ) );
29-
29+
3030 for( i = *start; i < max; i++ )
3131+ assigns( i )
3232+ loopInvariant( *start <= i && i <= max )
@@ -36,7 +36,7 @@ index d8694f0..761c44b 100644
3636 {
3737@@ -103,6 +121,13 @@ static size_t countHighBits( uint8_t c )
3838 size_t i = 0;
39-
39+
4040 while( ( n & 0x80U ) != 0U )
4141+ assigns( i, n )
4242+ loopInvariant (
@@ -61,9 +61,9 @@ index d8694f0..761c44b 100644
6161+ decreases( j )
6262 {
6363 i++;
64-
65- @@ -346 ,6 +378 ,12 @@ static bool skipOneHexEscape( const char * buf,
66- if( ( end < max ) && ( buf[ i ] == '\\' ) && ( buf[ i + 1U ] == 'u' ) )
64+
65+ @@ -343 ,6 +375 ,12 @@ static bool skipOneHexEscape( const char * buf,
66+ if( ( end > i ) && ( end < max ) && ( buf[ i ] == '\\' ) && ( buf[ i + 1U ] == 'u' ) )
6767 {
6868 for( i += 2U; i < end; i++ )
6969+ assigns( value, i )
@@ -74,50 +74,50 @@ index d8694f0..761c44b 100644
7474+ decreases( end - i )
7575 {
7676 uint8_t n = hexToInt( buf[ i ] );
77-
78- @@ -523 ,6 +561 ,9 @@ static bool skipString( const char * buf,
77+
78+ @@ -505 ,6 +543 ,9 @@ static bool skipString( const char * buf,
7979 i++;
80-
80+
8181 while( i < max )
8282+ assigns( i )
8383+ loopInvariant( *start + 1U <= i && i <= max )
8484+ decreases( max - i )
8585 {
8686 if( buf[ i ] == '"' )
8787 {
88- @@ -581 ,6 +622 ,9 @@ static bool strnEq( const char * a,
88+ @@ -563 ,6 +604 ,9 @@ static bool strnEq( const char * a,
8989 coreJSON_ASSERT( ( a != NULL ) && ( b != NULL ) );
90-
90+
9191 for( i = 0; i < n; i++ )
9292+ assigns( i )
9393+ loopInvariant( i <= n )
9494+ decreases( n - i )
9595 {
9696 if( a[ i ] != b[ i ] )
9797 {
98- @@ -696 ,6 +740 ,9 @@ static bool skipDigits( const char * buf,
98+ @@ -678 ,6 +722 ,9 @@ static bool skipDigits( const char * buf,
9999 saveStart = *start;
100-
100+
101101 for( i = *start; i < max; i++ )
102102+ assigns( value, i )
103103+ loopInvariant( *start <= i && i <= max )
104104+ decreases( max - i )
105105 {
106106 if( !isdigit_( buf[ i ] ) )
107107 {
108- @@ -945 ,6 +992 ,9 @@ static void skipArrayScalars( const char * buf,
108+ @@ -928 ,6 +975 ,9 @@ static bool skipArrayScalars( const char * buf,
109109 i = *start;
110-
110+
111111 while( i < max )
112112+ assigns( i )
113113+ loopInvariant( *start <= i && i <= max )
114114+ decreases( max - i )
115115 {
116116 if( skipAnyScalar( buf, &i, max ) != true )
117117 {
118- @@ -991 ,6 +1041 ,13 @@ static bool skipObjectScalars( const char * buf,
118+ @@ -982 ,6 +1032 ,13 @@ static bool skipObjectScalars( const char * buf,
119119 i = *start;
120-
120+
121121 while( i < max )
122122+ assigns( i, *start, comma )
123123+ loopInvariant(
@@ -129,11 +129,11 @@ index d8694f0..761c44b 100644
129129 {
130130 if( skipString( buf, &i, max ) != true )
131131 {
132- @@ -1118 ,6 +1175 ,14 @@ static JSONStatus_t skipCollection( const char * buf,
132+ @@ -1109 ,6 +1166 ,14 @@ static JSONStatus_t skipCollection( const char * buf,
133133 i = *start;
134-
134+
135135 while( i < max )
136- + assigns( i, depth, c, __CPROVER_object_whole( stack ), ret )
136+ + assigns( i, depth, c, ret, __CPROVER_object_whole( stack ) )
137137+ loopInvariant(
138138+ -1 <= depth && depth <= JSON_MAX_DEPTH
139139+ && *start <= i && i <= max
@@ -144,27 +144,35 @@ index d8694f0..761c44b 100644
144144 {
145145 c = buf[ i ];
146146 i++;
147- @@ -1407,6 +1472,9 @@ static bool objectSearch( const char * buf,
147+ @@ -1144,6 +1209,7 @@ static JSONStatus_t skipCollection( const char * buf,
148+
149+ if( skipSpaceAndComma( buf, &i, max ) == true )
150+ {
151+ + __CPROVER_assume( isOpenBracket_(stack[depth]));
152+ if( skipScalars( buf, &i, max, stack[ depth ] ) != true )
153+ {
154+ ret = JSONIllegalDocument;
155+ @@ -1406,6 +1472,9 @@ static bool objectSearch( const char * buf,
148156 skipSpace( buf, &i, max );
149-
157+
150158 while( i < max )
151159+ assigns( i, key, keyLength, value, valueLength )
152160+ loopInvariant( __CPROVER_loop_entry( i ) <= i && i <= max )
153161+ decreases( max - i )
154162 {
155163 if( nextKeyValuePair( buf, &i, max, &key, &keyLength,
156164 &value, &valueLength ) != true )
157- @@ -1474 ,6 +1542,9 @@ static bool arraySearch( const char * buf,
165+ @@ -1473 ,6 +1542,9 @@ static bool arraySearch( const char * buf,
158166 skipSpace( buf, &i, max );
159-
167+
160168 while( i < max )
161169+ assigns( i, currentIndex, value, valueLength )
162170+ loopInvariant( __CPROVER_loop_entry( i ) <= i && i <= max && currentIndex < i )
163171+ decreases( max - i )
164172 {
165173 if( nextValue( buf, &i, max, &value, &valueLength ) != true )
166174 {
167- @@ -1539 ,6 +1610,9 @@ static bool skipQueryPart( const char * buf,
175+ @@ -1538 ,6 +1610,9 @@ static bool skipQueryPart( const char * buf,
168176 while( ( i < max ) &&
169177 !isSeparator_( buf[ i ] ) &&
170178 !isSquareOpen_( buf[ i ] ) )
@@ -174,9 +182,9 @@ index d8694f0..761c44b 100644
174182 {
175183 i++;
176184 }
177- @@ -1585 ,6 +1659,17 @@ static JSONStatus_t multiSearch( const char * buf,
185+ @@ -1584 ,6 +1659,17 @@ static JSONStatus_t multiSearch( const char * buf,
178186 coreJSON_ASSERT( ( max > 0U ) && ( queryLength > 0U ) );
179-
187+
180188 while( i < queryLength )
181189+ assigns( i, start, queryStart, value, length )
182190+ loopInvariant(
@@ -191,4 +199,4 @@ index d8694f0..761c44b 100644
191199+ decreases( queryLength - i )
192200 {
193201 bool found = false;
194-
202+
0 commit comments