Skip to content
Myr

Fix assert in generator subexpressions (fix #1875)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Expressions of the form `path(EXPR) | select(GENERATOR)`, where `EXPR` is a path expression and `GENERATOR` is a generator conditional expression (e.g., `has("a"), has("b")`) cause an assertion if the jq_state VM is torn down too soon. That assert() was only correct if assuming that the conditional is not a generator. If the conditional is generator, then what we see is that when backtracking a SUBEXP_END is executed without a corresponding SUBEXP_BEGIN because the entire conditional is bracketed with SUBEXP_BEGIN and SUBEXP_END, and since it's resumed in the middle, in between the brackets. Rather than assert that the jq->path_len being restored has some particular value, we can simply re-compute it from the restored jq->path.

authored by Nicolas Williams · committed by Nicolas Williams · parent b34af08 · Browse files · 1 file+1 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+1 added−1 removed

  • other:+1 added−1 removed

1 file+1 added−1 removed

modified:src/execute.c+1 added-1 removed
290 unmodified lines
291 if (jv_get_kind(jq->path) == JV_KIND_ARRAY) {292 assert(path_len >= 0);293 jq->path = jv_array_slice(jq->path, 0, path_len);294 } else {295 assert(path_len == 0);295 fork->path_len = 0;296 }297 jv_free(jq->value_at_path);298 jq->value_at_path = fork->value_at_path;299 jq->subexp_nest = fork->subexp_nest;
959 unmodified lines