From 5686e93bba2100a05fae262a1485f5af8b82c892 Mon Sep 17 00:00:00 2001 From: Emanuele Torre Date: Sat, 28 Oct 2023 23:58:03 +0200 Subject: [PATCH 1/2] jvp_object_contains: remove unnecessary jv_copy --- src/jv.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/jv.c b/src/jv.c index eec4ec5ad1..ada15fedf9 100644 --- a/src/jv.c +++ b/src/jv.c @@ -1729,10 +1729,9 @@ static int jvp_object_contains(jv a, jv b) { int r = 1; jv_object_foreach(b, key, b_val) { - jv a_val = jv_object_get(jv_copy(a), jv_copy(key)); + jv a_val = jv_object_get(jv_copy(a), key); r = jv_contains(a_val, b_val); - jv_free(key); if (!r) break; } From f8d475c45c64fe4ca86aca056e6904d92e23e50d Mon Sep 17 00:00:00 2001 From: Emanuele Torre Date: Sun, 29 Oct 2023 04:30:01 +0100 Subject: [PATCH 2/2] src/builtin.c: remove unnecessary jv_copy-s in type_error/type_error2 Also fix doubled semicolon jv ret;; => jv ret; --- src/builtin.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/builtin.c b/src/builtin.c index 2ea40dc54f..cf4792c446 100644 --- a/src/builtin.c +++ b/src/builtin.c @@ -58,24 +58,23 @@ BINOPS static jv type_error(jv bad, const char* msg) { char errbuf[15]; - jv err = jv_invalid_with_msg(jv_string_fmt("%s (%s) %s", - jv_kind_name(jv_get_kind(bad)), - jv_dump_string_trunc(jv_copy(bad), errbuf, sizeof(errbuf)), + const char *badkind = jv_kind_name(jv_get_kind(bad)); + jv err = jv_invalid_with_msg(jv_string_fmt("%s (%s) %s", badkind, + jv_dump_string_trunc(bad, errbuf, sizeof(errbuf)), msg)); - jv_free(bad); return err; } static jv type_error2(jv bad1, jv bad2, const char* msg) { char errbuf1[15],errbuf2[15]; + const char *badkind1 = jv_kind_name(jv_get_kind(bad1)); + const char *badkind2 = jv_kind_name(jv_get_kind(bad2)); jv err = jv_invalid_with_msg(jv_string_fmt("%s (%s) and %s (%s) %s", - jv_kind_name(jv_get_kind(bad1)), - jv_dump_string_trunc(jv_copy(bad1), errbuf1, sizeof(errbuf1)), - jv_kind_name(jv_get_kind(bad2)), - jv_dump_string_trunc(jv_copy(bad2), errbuf2, sizeof(errbuf2)), + badkind1, + jv_dump_string_trunc(bad1, errbuf1, sizeof(errbuf1)), + badkind2, + jv_dump_string_trunc(bad2, errbuf2, sizeof(errbuf2)), msg)); - jv_free(bad1); - jv_free(bad2); return err; } @@ -283,7 +282,7 @@ static jv f_endswith(jq_state *jq, jv a, jv b) { const char *bstr = jv_string_value(b); size_t alen = jv_string_length_bytes(jv_copy(a)); size_t blen = jv_string_length_bytes(jv_copy(b)); - jv ret;; + jv ret; if (alen < blen || memcmp(astr + (alen - blen), bstr, blen) != 0)