diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2016-02-03 18:32:55 +0100 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2016-02-03 18:32:55 +0100 |
commit | 0c5f596da75c58a1fd0999133e18291a680dd040 (patch) | |
tree | c9478bb5ecb6c6fefc7b829368e71e60ce4b08cf | |
parent | 691f1065ad33b5d53d342e8705a37563d9ebb8b5 (diff) | |
download | jsonpath-0c5f596da75c58a1fd0999133e18291a680dd040.tar.gz |
matcher: fix segfault with subscript on non-array element
Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
-rw-r--r-- | matcher.c | 17 |
1 files changed, 10 insertions, 7 deletions
@@ -258,16 +258,19 @@ jp_match_next(struct jp_opcode *ptr, break; case T_NUMBER: - idx = ptr->num; + if (json_object_get_type(cur) == json_type_array) + { + idx = ptr->num; - if (idx < 0) - idx += json_object_array_length(cur); + if (idx < 0) + idx += json_object_array_length(cur); - if (idx >= 0) - next = json_object_array_get_idx(cur, idx); + if (idx >= 0) + next = json_object_array_get_idx(cur, idx); - if (next) - return jp_match_next(ptr->sibling, root, next, cb, priv); + if (next) + return jp_match_next(ptr->sibling, root, next, cb, priv); + } break; |