@@ -1363,6 +1363,7 @@ fixJSON(struct ln_pdag *dag,
13631363 /* Free the unneeded value */
13641364 json_object_put (* value );
13651365 }
1366+ * value = NULL ;
13661367 } else if (prs -> name [0 ] == '.' && prs -> name [1 ] == '\0' ) {
13671368 if (json_object_get_type (* value ) == json_type_object ) {
13681369 struct json_object_iterator it = json_object_iter_begin (* value );
@@ -1417,6 +1418,7 @@ fixJSON(struct ln_pdag *dag,
14171418 }
14181419 }
14191420 r = 0 ;
1421+ * value = NULL ;
14201422 return r ;
14211423}
14221424
@@ -1588,7 +1590,7 @@ ln_normalizeRec(npb_t *const __restrict__ npb,
15881590 size_t iprs ;
15891591 size_t parsedTo = npb -> parsedTo ;
15901592 size_t parsed = 0 ;
1591- struct json_object * value ;
1593+ struct json_object * value = NULL ;
15921594
15931595LN_DBGPRINTF (dag -> ctx , "%zu: enter parser, dag node %p, json %p" , offs , dag , json );
15941596
@@ -1614,7 +1616,6 @@ LN_DBGPRINTF(dag->ctx, "%zu: enter parser, dag node %p, json %p", offs, dag, jso
16141616 : "UNKNOWN" );
16151617 }
16161618 i = offs ;
1617- value = NULL ;
16181619 localR = tryParser (npb , dag , & i , & parsed , & value , prs , failOnDuplicate , json , prs -> name );
16191620 if (localR == 0 ) {
16201621 parsedTo = i + parsed ;
@@ -1628,9 +1629,14 @@ LN_DBGPRINTF(dag->ctx, "%zu: enter parser, dag node %p, json %p", offs, dag, jso
16281629 if (r == 0 ) {
16291630 LN_DBGPRINTF (dag -> ctx , "%zu: parser matches at %zu" , offs , i );
16301631 CHKR (fixJSON (dag , & value , json , prs ));
1632+ value = NULL ;
16311633 if (npb -> ctx -> opts & LN_CTXOPT_ADD_RULE ) {
16321634 add_rule_to_mockup (npb , prs );
16331635 }
1636+ /* did we have a longer parser --> then update */
1637+ if (parsedTo > npb -> parsedTo )
1638+ npb -> parsedTo = parsedTo ;
1639+
16341640 } else {
16351641 ++ dag -> stats .backtracked ;
16361642 #ifdef ADVANCED_STATS
@@ -1639,14 +1645,16 @@ LN_DBGPRINTF(dag->ctx, "%zu: enter parser, dag node %p, json %p", offs, dag, jso
16391645 #endif
16401646 LN_DBGPRINTF (dag -> ctx , "%zu nonmatch, backtracking required, parsed to=%zu" ,
16411647 offs , parsedTo );
1642- if (value != NULL ) { /* Free the value if it was created */
1643- json_object_put (value );
1644- }
16451648 }
16461649 }
1650+ if (value != NULL ) { /* Free the value if it was created */
1651+ json_object_put (value );
1652+ value = NULL ;
1653+ }
1654+
16471655 /* did we have a longer parser --> then update */
1648- if (parsedTo > npb -> parsedTo )
1649- npb -> parsedTo = parsedTo ;
1656+ if (parsedTo > npb -> longestParsedTo )
1657+ npb -> longestParsedTo = parsedTo ;
16501658 LN_DBGPRINTF (dag -> ctx , "parsedTo %zu, *pParsedTo %zu" , parsedTo , npb -> parsedTo );
16511659 }
16521660
@@ -1725,7 +1733,7 @@ ln_normalize(ln_ctx ctx, const char *str, const size_t strLen, struct json_objec
17251733 addRuleMetadata (& npb , * json_p , endNode );
17261734 r = 0 ;
17271735 } else {
1728- addUnparsedField (str , strLen , npb .parsedTo , * json_p );
1736+ addUnparsedField (str , strLen , npb .longestParsedTo , * json_p );
17291737 }
17301738
17311739 if (ctx -> opts & LN_CTXOPT_ADD_RULE ) {
0 commit comments