curl_json plugin: Fix array index and key handling.
authorFlorian Forster <octo@collectd.org>
Mon, 15 May 2017 12:40:26 +0000 (14:40 +0200)
committerFlorian Forster <octo@collectd.org>
Tue, 16 May 2017 17:29:24 +0000 (19:29 +0200)
Previously, the "key" was loaded by calling cj_cb_map_key() from
cj_cb_inc_array_index(). That means that the key for the previous element
was loaded as the array index was updated for the next element, resulting
in an off-by-one error. Also the key was not unset in time, resulting in
two metrics with the same identifier being created.

This patch fixes this with the following changes:

*   cj_advance_array() (nee cj_cb_inc_array_index()) now loads the key for
    the new index position instead of the previous one.
*   The initial "0" key is loaded from cj_cb_start_array().
*   cj_advance_array() always updates the key. The "update_key" argument
    has been removed.
*   Refactoring: key loading has been moved out of cj_cb_map_key() and
    into its own function, cj_load_key().

Unit tests are in a separate commit for easier cherry-picking.

Fixes: #2266


No differences found