@@ -1745,6 +1745,7 @@ each_worker_jsonb(FunctionCallInfo fcinfo, const char *funcname, bool as_text)
17451745 * matter what shape it is.
17461746 */
17471747 r = JsonbIteratorNext (& it , & v , skipNested );
1748+ Assert (r != WJB_DONE );
17481749
17491750 values [0 ] = PointerGetDatum (key );
17501751
@@ -4111,6 +4112,7 @@ addJsonbToParseState(JsonbParseState **jbps, Jsonb *jb)
41114112 if (JB_ROOT_IS_SCALAR (jb ))
41124113 {
41134114 (void ) JsonbIteratorNext (& it , & v , false); /* skip array header */
4115+ Assert (v .type == jbvArray );
41144116 (void ) JsonbIteratorNext (& it , & v , false); /* fetch scalar value */
41154117
41164118 switch (o -> type )
@@ -4224,7 +4226,7 @@ jsonb_delete(PG_FUNCTION_ARGS)
42244226
42254227 it = JsonbIteratorInit (& in -> root );
42264228
4227- while ((r = JsonbIteratorNext (& it , & v , skipNested )) != 0 )
4229+ while ((r = JsonbIteratorNext (& it , & v , skipNested )) != WJB_DONE )
42284230 {
42294231 skipNested = true;
42304232
@@ -4234,7 +4236,7 @@ jsonb_delete(PG_FUNCTION_ARGS)
42344236 {
42354237 /* skip corresponding value as well */
42364238 if (r == WJB_KEY )
4237- JsonbIteratorNext (& it , & v , true);
4239+ ( void ) JsonbIteratorNext (& it , & v , true);
42384240
42394241 continue ;
42404242 }
@@ -4289,7 +4291,7 @@ jsonb_delete_array(PG_FUNCTION_ARGS)
42894291
42904292 it = JsonbIteratorInit (& in -> root );
42914293
4292- while ((r = JsonbIteratorNext (& it , & v , skipNested )) != 0 )
4294+ while ((r = JsonbIteratorNext (& it , & v , skipNested )) != WJB_DONE )
42934295 {
42944296 skipNested = true;
42954297
@@ -4319,7 +4321,7 @@ jsonb_delete_array(PG_FUNCTION_ARGS)
43194321 {
43204322 /* skip corresponding value as well */
43214323 if (r == WJB_KEY )
4322- JsonbIteratorNext (& it , & v , true);
4324+ ( void ) JsonbIteratorNext (& it , & v , true);
43234325
43244326 continue ;
43254327 }
@@ -4385,7 +4387,7 @@ jsonb_delete_idx(PG_FUNCTION_ARGS)
43854387
43864388 pushJsonbValue (& state , r , NULL );
43874389
4388- while ((r = JsonbIteratorNext (& it , & v , true)) != 0 )
4390+ while ((r = JsonbIteratorNext (& it , & v , true)) != WJB_DONE )
43894391 {
43904392 if (r == WJB_ELEM )
43914393 {
@@ -4576,7 +4578,7 @@ IteratorConcat(JsonbIterator **it1, JsonbIterator **it2,
45764578 * Append the all tokens from v2 to res, include last WJB_END_OBJECT
45774579 * (the concatenation will be completed).
45784580 */
4579- while ((r2 = JsonbIteratorNext (it2 , & v2 , true)) != 0 )
4581+ while ((r2 = JsonbIteratorNext (it2 , & v2 , true)) != WJB_DONE )
45804582 res = pushJsonbValue (state , r2 , r2 != WJB_END_OBJECT ? & v2 : NULL );
45814583 }
45824584
@@ -4616,10 +4618,10 @@ IteratorConcat(JsonbIterator **it1, JsonbIterator **it2,
46164618 if (prepend )
46174619 {
46184620 pushJsonbValue (state , WJB_BEGIN_OBJECT , NULL );
4619- while ((r1 = JsonbIteratorNext (it_object , & v1 , true)) != 0 )
4621+ while ((r1 = JsonbIteratorNext (it_object , & v1 , true)) != WJB_DONE )
46204622 pushJsonbValue (state , r1 , r1 != WJB_END_OBJECT ? & v1 : NULL );
46214623
4622- while ((r2 = JsonbIteratorNext (it_array , & v2 , true)) != 0 )
4624+ while ((r2 = JsonbIteratorNext (it_array , & v2 , true)) != WJB_DONE )
46234625 res = pushJsonbValue (state , r2 , r2 != WJB_END_ARRAY ? & v2 : NULL );
46244626 }
46254627 else
@@ -4628,7 +4630,7 @@ IteratorConcat(JsonbIterator **it1, JsonbIterator **it2,
46284630 pushJsonbValue (state , r1 , & v1 );
46294631
46304632 pushJsonbValue (state , WJB_BEGIN_OBJECT , NULL );
4631- while ((r2 = JsonbIteratorNext (it_object , & v2 , true)) != 0 )
4633+ while ((r2 = JsonbIteratorNext (it_object , & v2 , true)) != WJB_DONE )
46324634 pushJsonbValue (state , r2 , r2 != WJB_END_OBJECT ? & v2 : NULL );
46334635
46344636 res = pushJsonbValue (state , WJB_END_ARRAY , NULL );
@@ -4959,7 +4961,7 @@ parse_jsonb_index_flags(Jsonb *jb)
49594961
49604962 /*
49614963 * We iterate over array (scalar internally is represented as array, so, we
4962- * will accept it too) to check all its elements. Flag's names are choosen
4964+ * will accept it too) to check all its elements. Flag names are chosen
49634965 * the same as jsonb_typeof uses.
49644966 */
49654967 if (type != WJB_BEGIN_ARRAY )
@@ -4997,12 +4999,14 @@ parse_jsonb_index_flags(Jsonb *jb)
49974999 errhint ("Possible values are: \"string\", \"numeric\", \"boolean\", \"key\" and \"all\"" )));
49985000 }
49995001
5000- /* user should not get it */
5002+ /* expect end of array now */
50015003 if (type != WJB_END_ARRAY )
50025004 elog (ERROR , "unexpected end of flag array" );
50035005
50045006 /* get final WJB_DONE and free iterator */
5005- JsonbIteratorNext (& it , & v , false);
5007+ type = JsonbIteratorNext (& it , & v , false);
5008+ if (type != WJB_DONE )
5009+ elog (ERROR , "unexpected end of flag array" );
50065010
50075011 return flags ;
50085012}
0 commit comments