diff options
author | Nicolas Williams <nico@cryptonector.com> | 2019-02-08 20:39:36 -0600 |
---|---|---|
committer | Nicolas Williams <nico@cryptonector.com> | 2019-02-08 20:40:55 -0600 |
commit | 2660b04a731568c54eb4b91fe811d81cbbf3470b (patch) | |
tree | a3f99840574d3bf3c1fc2b4947d73215f25c6c68 | |
parent | 18ac789d6d74f198053c547fba4e8c70cb99d55a (diff) |
Fix infinite loop in index("") (fix #1815)
-rw-r--r-- | src/jv.c | 2 | ||||
-rw-r--r-- | tests/jq.test | 5 |
2 files changed, 7 insertions, 0 deletions
@@ -658,6 +658,8 @@ jv jv_string_indexes(jv j, jv k) { int idxlen = jv_string_length_bytes(jv_copy(k)); jv a = jv_array(); + if (idxlen == 0) + return a; p = jstr; while ((p = _jq_memmem(p, (jstr + jlen) - p, idxstr, idxlen)) != NULL) { a = jv_array_append(a, jv_number(p - jstr)); diff --git a/tests/jq.test b/tests/jq.test index 6ee657b6..1572043e 100644 --- a/tests/jq.test +++ b/tests/jq.test @@ -1538,4 +1538,9 @@ isempty(1,error("foo")) null false +# Regression test for #1815 +index("") +"" +null + |