summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilliam Langford <wlangfor@gmail.com>2019-02-22 19:33:24 -0500
committerNico Williams <nico@cryptonector.com>2019-02-26 11:10:38 -0600
commitf951d0241c8808ae6c0672dca7d51fec28c9fb9f (patch)
treebadbbb8ea958eb7bd0c511c5aeec693b7cf0e678
parentcc724f105d9bac5abd4ba98e3bb85795f7e9f380 (diff)
Change contains to return true for empty string needles
The behavior of memmem for an empty needle is inconsistent between implementations of libc. Our tests imply that we want an empty string needle to be true, so check for an empty needle before calling memmem.
-rw-r--r--src/jv.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/jv.c b/src/jv.c
index 06b4e6a2..2427b009 100644
--- a/src/jv.c
+++ b/src/jv.c
@@ -1344,8 +1344,13 @@ int jv_contains(jv a, jv b) {
} else if (jv_get_kind(a) == JV_KIND_ARRAY) {
r = jv_array_contains(jv_copy(a), jv_copy(b));
} else if (jv_get_kind(a) == JV_KIND_STRING) {
- r = _jq_memmem(jv_string_value(a), jv_string_length_bytes(jv_copy(a)),
- jv_string_value(b), jv_string_length_bytes(jv_copy(b))) != 0;
+ int b_len = jv_string_length_bytes(jv_copy(b));
+ if (b_len != 0) {
+ r = _jq_memmem(jv_string_value(a), jv_string_length_bytes(jv_copy(a)),
+ jv_string_value(b), b_len) != 0;
+ } else {
+ r = 1;
+ }
} else {
r = jv_equal(jv_copy(a), jv_copy(b));
}