From 8677c07fd61e6accf5bd7a9fd4de670bb22c98cd Mon Sep 17 00:00:00 2001 From: Emanuele Torre Date: Thu, 28 Sep 2023 03:19:53 +0200 Subject: [PATCH 1/2] Remove unused nref accumulator in block_bind_library detected as a warning compiling jq with clang. --- src/compile.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/compile.c b/src/compile.c index 76d4bcbce6..467ea2b0ad 100644 --- a/src/compile.c +++ b/src/compile.c @@ -372,7 +372,6 @@ static block block_bind(block binder, block body, int bindflags) { block block_bind_library(block binder, block body, int bindflags, const char *libname) { bindflags |= OP_HAS_BINDING; - int nrefs = 0; int matchlen = (libname == NULL) ? 0 : strlen(libname); char *matchname = jv_mem_alloc(matchlen+2+1); matchname[0] = '\0'; @@ -395,7 +394,7 @@ block block_bind_library(block binder, block body, int bindflags, const char *li // This mutation is ugly, even if we undo it curr->symbol = tname; - nrefs += block_bind_subblock(inst_block(curr), body, bindflags2, 0); + block_bind_subblock(inst_block(curr), body, bindflags2, 0); curr->symbol = cname; free(tname); } From 308f301d28255b235e904193d44b3a726be58ce8 Mon Sep 17 00:00:00 2001 From: Emanuele Torre Date: Thu, 28 Sep 2023 03:20:49 +0200 Subject: [PATCH 2/2] Remove a bunch of unused variables, and useless assignments Detected by clang-tidy. --- src/execute.c | 2 +- src/jq_test.c | 1 - src/jv.c | 3 +-- src/util.c | 2 +- 4 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/execute.c b/src/execute.c index 02af823214..9ef8368329 100644 --- a/src/execute.c +++ b/src/execute.c @@ -1242,7 +1242,7 @@ int jq_compile_args(jq_state *jq, const char* str, jv args) { if (nerrors == 0) { nerrors = builtins_bind(jq, &program); if (nerrors == 0) { - nerrors = block_compile(program, &jq->bc, locations, args = args2obj(args)); + nerrors = block_compile(program, &jq->bc, locations, args2obj(args)); } } else jv_free(args); diff --git a/src/jq_test.c b/src/jq_test.c index 4505c19a54..39456861a5 100644 --- a/src/jq_test.c +++ b/src/jq_test.c @@ -127,7 +127,6 @@ static void run_jq_tests(jv lib_dirs, int verbose, FILE *testdata, int skip, int take--; } else if (take == 0) { printf("Hit the number of tests limit (%d), breaking\n", tests_to_take); - take = -1; break; } diff --git a/src/jv.c b/src/jv.c index 8554169494..eec4ec5ad1 100644 --- a/src/jv.c +++ b/src/jv.c @@ -1080,14 +1080,13 @@ static jvp_string* jvp_string_alloc(uint32_t size) { static jv jvp_string_copy_replace_bad(const char* data, uint32_t length) { const char* end = data + length; const char* i = data; - const char* cstart; uint32_t maxlength = length * 3 + 1; // worst case: all bad bytes, each becomes a 3-byte U+FFFD jvp_string* s = jvp_string_alloc(maxlength); char* out = s->data; int c = 0; - while ((i = jvp_utf8_next((cstart = i), end, &c))) { + while ((i = jvp_utf8_next(i, end, &c))) { if (c == -1) { c = 0xFFFD; // U+FFFD REPLACEMENT CHARACTER } diff --git a/src/util.c b/src/util.c index e35eb9067d..2f961e3c81 100644 --- a/src/util.c +++ b/src/util.c @@ -353,7 +353,7 @@ static int jq_util_input_read_more(jq_util_input_state *state) { * terminating '\0'. This only works because we previously memset our * buffer with something nonzero. */ - for (p = state->buf, i = sizeof(state->buf) - 1; i > 0; i--) { + for (i = sizeof(state->buf) - 1; i > 0; i--) { if (state->buf[i] == '\0') break; }