From: Jo-Philipp Wich Date: Wed, 3 Feb 2016 17:32:55 +0000 (+0100) Subject: matcher: fix segfault with subscript on non-array element X-Git-Url: http://git.openwrt.org/?p=project%2Fjsonpath.git;a=commitdiff_plain;h=0c5f596da75c58a1fd0999133e18291a680dd040 matcher: fix segfault with subscript on non-array element Signed-off-by: Jo-Philipp Wich --- diff --git a/matcher.c b/matcher.c index ceb756e..e657395 100644 --- a/matcher.c +++ b/matcher.c @@ -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;