diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2014-06-19 12:08:08 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2014-06-19 14:00:21 +0200 |
commit | 6f49eeec51e1697496d97479d41ff31cb4563270 (patch) | |
tree | 15c5297366f471e010cc66bf3f79cd236ad811eb | |
parent | 96aad161dbbae98ecc042dc6ef4312ec7ea26057 (diff) | |
download | jsonpath-6f49eeec51e1697496d97479d41ff31cb4563270.tar.gz |
matcher.c: properly handle negative array indizes
Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
-rw-r--r-- | matcher.c | 11 |
1 files changed, 9 insertions, 2 deletions
@@ -237,7 +237,8 @@ jp_match_next(struct jp_opcode *ptr, struct json_object *root, struct json_object *cur, jp_match_cb_t cb, void *priv) { - struct json_object *next; + int idx; + struct json_object *next = NULL; if (!ptr) { @@ -257,7 +258,13 @@ jp_match_next(struct jp_opcode *ptr, break; case T_NUMBER: - next = json_object_array_get_idx(cur, ptr->num); + idx = ptr->num; + + if (idx < 0) + idx += json_object_array_length(cur); + + if (idx >= 0) + next = json_object_array_get_idx(cur, idx); if (next) return jp_match_next(ptr->sibling, root, next, cb, priv); |