diff --git a/src/builtin.cpp b/src/builtin.cpp index eacaaf394..e173d157f 100644 --- a/src/builtin.cpp +++ b/src/builtin.cpp @@ -3299,13 +3299,11 @@ static bool builtin_handles_help(const wchar_t *cmd) { /// Execute a builtin command int builtin_run(parser_t &parser, const wchar_t *const *argv, io_streams_t &streams) { - int (*cmd)(parser_t & parser, io_streams_t & streams, const wchar_t *const *argv) = NULL; + UNUSED(parser); + UNUSED(streams); if (argv == NULL || argv[0] == NULL) return STATUS_BUILTIN_ERROR; const builtin_data_t *data = builtin_lookup(argv[0]); - cmd = (int (*)(parser_t & parser, io_streams_t & streams, const wchar_t *const *))( - data ? data->func : NULL); - if (argv[1] != NULL && !builtin_handles_help(argv[0]) && argv[2] == NULL && parse_util_argument_is_help(argv[1], 0)) { builtin_print_help(parser, streams, argv[0], streams.out); @@ -3313,7 +3311,13 @@ int builtin_run(parser_t &parser, const wchar_t *const *argv, io_streams_t &stre } if (data != NULL) { - return cmd(parser, streams, argv); + // Warning: layering violation and naughty cast. The code originally had a much more + // complicated solution to achieve exactly the same result: lie about the constness of argv. + // Some of the builtins we call do mutate the array via their calls to wgetopt() which could + // result in the pointers being reordered. This is harmless because we only get called once + // with a given argv array and nothing else will look at the contents of the array after we + // return. + return data->func(parser, streams, (wchar_t **)argv); } debug(0, UNKNOWN_BUILTIN_ERR_MSG, argv[0]); diff --git a/src/builtin_string.cpp b/src/builtin_string.cpp index eb8e7e2f1..af7cfae27 100644 --- a/src/builtin_string.cpp +++ b/src/builtin_string.cpp @@ -1159,7 +1159,8 @@ static int string_trim(parser_t &parser, io_streams_t &streams, int argc, wchar_ static const struct string_subcommand { const wchar_t *name; - int (*handler)(parser_t &, io_streams_t &, int argc, wchar_t **argv); + int (*handler)(parser_t &, io_streams_t &, int argc, //!OCLINT(unused param) + wchar_t **argv); //!OCLINT(unused param) } string_subcommands[] = { diff --git a/src/expand.cpp b/src/expand.cpp index ef1cd613f..26d2a5f6d 100644 --- a/src/expand.cpp +++ b/src/expand.cpp @@ -1302,8 +1302,10 @@ static void remove_internal_separator(wcstring *str, bool conv) { /// A stage in string expansion is represented as a function that takes an input and returns a list /// of output (by reference). We get flags and errors. It may return an error; if so expansion /// halts. -typedef expand_error_t (*expand_stage_t)(const wcstring &input, std::vector *out, - expand_flags_t flags, parse_error_list_t *errors); +typedef expand_error_t (*expand_stage_t)(const wcstring &input, //!OCLINT(unused param) + std::vector *out, //!OCLINT(unused param) + expand_flags_t flags, //!OCLINT(unused param) + parse_error_list_t *errors); //!OCLINT(unused param) static expand_error_t expand_stage_cmdsubst(const wcstring &input, std::vector *out, expand_flags_t flags, parse_error_list_t *errors) { diff --git a/src/history.cpp b/src/history.cpp index 82c894aaa..554d521bf 100644 --- a/src/history.cpp +++ b/src/history.cpp @@ -769,7 +769,7 @@ void history_t::save_internal_unless_disabled() { } // This might be a good candidate for moving to a background thread. - time_profiler_t profiler(vacuum ? "save_internal vacuum" + time_profiler_t profiler(vacuum ? "save_internal vacuum" //!OCLINT(unused var) : "save_internal no vacuum"); //!OCLINT(side-effect) this->save_internal(vacuum); diff --git a/src/output.cpp b/src/output.cpp index 03c1f9fa5..271ddae5f 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -32,7 +32,7 @@ static int writeb_internal(char c); /// The function used for output. -static int (*out)(char c) = writeb_internal; +static int (*out)(char c) = writeb_internal; //!OCLINT(unused param) /// Whether term256 and term24bit are supported. static color_support_t color_support = 0; diff --git a/src/parse_productions.cpp b/src/parse_productions.cpp index 1b577d6ed..b3d976905 100644 --- a/src/parse_productions.cpp +++ b/src/parse_productions.cpp @@ -428,6 +428,7 @@ RESOLVE_ONLY(end_command) = {KEYWORD(parse_keyword_end)}; case (symbol_##sym): \ resolver = resolve_##sym; \ break; + const production_t *parse_productions::production_for_token(parse_token_type_t node_type, const parse_token_t &input1, const parse_token_t &input2, @@ -436,8 +437,9 @@ const production_t *parse_productions::production_for_token(parse_token_type_t n token_type_description(node_type), input1.describe().c_str()); // Fetch the function to resolve the list of productions. - const production_t *(*resolver)(const parse_token_t &input1, const parse_token_t &input2, - parse_node_tag_t *out_tag) = NULL; + const production_t *(*resolver)(const parse_token_t &input1, //!OCLINT(unused param) + const parse_token_t &input2, //!OCLINT(unused param) + parse_node_tag_t *out_tag) = NULL; //!OCLINT(unused param) switch (node_type) { TEST(job_list) TEST(job) diff --git a/src/wildcard.cpp b/src/wildcard.cpp index 43659995f..38f226a1b 100644 --- a/src/wildcard.cpp +++ b/src/wildcard.cpp @@ -846,7 +846,6 @@ void wildcard_expander_t::expand(const wcstring &base_dir, const wchar_t *wc, } else { // Not the last segment, nonempty wildcard. assert(next_slash != NULL); - wcstring child_effective_prefix = effective_prefix + wc_segment; this->expand_intermediate_segment(base_dir, dir, wc_segment, wc_remainder, effective_prefix + wc_segment + L'/'); }