Fix off by one error in JSON extract path code.
authorAndrew Dunstan <andrew@dunslane.net>
Thu, 4 Apr 2013 22:26:52 +0000 (18:26 -0400)
committerAndrew Dunstan <andrew@dunslane.net>
Thu, 4 Apr 2013 22:26:52 +0000 (18:26 -0400)
Bug report by David Wheeler, diagnosis assistance from Tom Lane.

src/backend/utils/adt/jsonfuncs.c

index 63df1ac6777e3fff1189da6aa7d72888c87cb201..73bcdf46b1266e449af5db50b8bc712b55760098 100644 (file)
@@ -682,9 +682,13 @@ get_array_start(void *state)
        ereport(ERROR,
                (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                 errmsg("cannot extract field from a non-object")));
-   /* initialize array count for this nesting level */
+   /* 
+    * initialize array count for this nesting level 
+    * Note: the lex_level seen by array_start is one less than that seen by
+    * the elements of the array.
+    */
    if (_state->search_type == JSON_SEARCH_PATH &&
-       lex_level <= _state->npath)
+       lex_level < _state->npath)
        _state->array_level_index[lex_level] = -1;
 }