From cccc72f3c1935294dd2c51b44ad30f409f3a6e7a Mon Sep 17 00:00:00 2001 From: Tim Stack Date: Thu, 13 Jun 2024 13:45:09 -0700 Subject: [PATCH] [coverity] moare fixes --- src/base/attr_line.hh | 3 ++ src/base/future_util.hh | 2 +- src/base/isc.hh | 30 ++++++++++------- src/base/lnav.console.hh | 3 ++ src/base/piper.file.cc | 24 ++++++++----- src/field_overlay_source.cc | 21 +++++++----- src/hotkeys.cc | 3 +- src/log_format.cc | 18 ++++++---- src/logfile_sub_source.cc | 3 +- src/vtab_module.hh | 67 +++++++++++++++++-------------------- 10 files changed, 100 insertions(+), 74 deletions(-) diff --git a/src/base/attr_line.hh b/src/base/attr_line.hh index bc325646..df75119c 100644 --- a/src/base/attr_line.hh +++ b/src/base/attr_line.hh @@ -584,6 +584,9 @@ public: void apply_hide(); + attr_line_t move() & { return std::move(*this); } + attr_line_t move() && { return std::move(*this); } + std::string al_string; string_attrs_t al_attrs; }; diff --git a/src/base/future_util.hh b/src/base/future_util.hh index ad57459a..0376adea 100644 --- a/src/base/future_util.hh +++ b/src/base/future_util.hh @@ -74,7 +74,7 @@ public: explicit future_queue( std::function&)> processor, size_t max_queue_size = 8) - : fq_processor(processor), fq_max_queue_size(max_queue_size) + : fq_processor(std::move(processor)), fq_max_queue_size(max_queue_size) { } diff --git a/src/base/isc.hh b/src/base/isc.hh index 339dcaff..3bbeafc6 100644 --- a/src/base/isc.hh +++ b/src/base/isc.hh @@ -166,7 +166,7 @@ protected: template class service : public service_base { public: - explicit service(std::string sub_name = "") + explicit service(const std::string& sub_name = "") : service_base(std::string(__PRETTY_FUNCTION__) + " " + sub_name) { } @@ -174,9 +174,11 @@ public: template void send(F msg) { - this->s_port.send({[lifetime = this->shared_from_this(), this, msg]() { - msg(*(static_cast(this))); - }}); + this->s_port.send({ + [lifetime = this->shared_from_this(), + this, + msg2 = std::move(msg)]() { msg2(*(static_cast(this))); }, + }); } template @@ -185,12 +187,16 @@ public: { msg_port reply_port; - this->s_port.send( - {[lifetime = this->shared_from_this(), this, &reply_port, msg]() { - msg(*(static_cast(this))); + this->s_port.send({ + [lifetime = this->shared_from_this(), + this, + &reply_port, + msg2 = std::move(msg)]() { + msg2(*(static_cast(this))); reply_port.send(empty_msg()); - }}); - reply_port.template process_for(rel_time); + }, + }); + reply_port.process_for(rel_time); } }; @@ -200,7 +206,7 @@ struct to { { auto& service = injector::get(); - service.send(cb); + service.send(std::move(cb)); } template @@ -209,14 +215,14 @@ struct to { { auto& service = injector::get(); - service.send_and_wait(cb, rel_time); + service.send_and_wait(std::move(cb), rel_time); } void send_and_wait(std::function cb) { using namespace std::literals::chrono_literals; - this->send_and_wait(cb, 48h); + this->send_and_wait(std::move(cb), 48h); } }; diff --git a/src/base/lnav.console.hh b/src/base/lnav.console.hh index 018fab48..00c2d874 100644 --- a/src/base/lnav.console.hh +++ b/src/base/lnav.console.hh @@ -193,6 +193,9 @@ struct user_message { attr_line_t to_attr_line(std::set flags = {render_flags::prefix}) const; + user_message move() & { return std::move(*this); } + user_message move() && { return std::move(*this); } + level um_level{level::ok}; attr_line_t um_message; std::vector um_snippets; diff --git a/src/base/piper.file.cc b/src/base/piper.file.cc index 7d8a7dd0..4853194a 100644 --- a/src/base/piper.file.cc +++ b/src/base/piper.file.cc @@ -114,7 +114,7 @@ multiplex_matcher::match(const string_fragment& line) if (!md[df.dd_muxid_capture_index].has_value()) { log_info(" however, mux_id was not captured"); - auto match_um = lnav::console::user_message::warning( + const auto match_um = lnav::console::user_message::warning( attr_line_t("demuxer ") .append_quoted(demux_pair.first) .append(" matched, however the ") @@ -125,7 +125,7 @@ multiplex_matcher::match(const string_fragment& line) } if (!md[df.dd_body_capture_index].has_value()) { log_info(" however, body was not captured"); - auto match_um = lnav::console::user_message::warning( + const auto match_um = lnav::console::user_message::warning( attr_line_t("demuxer ") .append_quoted(demux_pair.first) .append(" matched, however the ") @@ -146,10 +146,13 @@ multiplex_matcher::match(const string_fragment& line) this->mm_details.emplace_back(match_um); return found{demux_pair.first}; } - auto config_al = attr_line_t().append( - fmt::format(FMT_STRING(":config /log/demux/{}/enabled " - "true"), - demux_pair.first)); + auto config_al + = attr_line_t() + .append(fmt::format( + FMT_STRING(":config /log/demux/{}/enabled " + "true"), + demux_pair.first)) + .move(); readline_lnav_highlighter(config_al, -1); auto match_um = lnav::console::user_message::info( @@ -163,7 +166,8 @@ multiplex_matcher::match(const string_fragment& line) attr_line_t("Use ") .append_quoted( lnav::roles::quoted_code(config_al)) - .append(" to enable this demuxer")); + .append(" to enable this demuxer")) + .move(); this->mm_details.emplace_back(match_um); } @@ -184,14 +188,16 @@ multiplex_matcher::match(const string_fragment& line) .append(lnav::roles::quoted_code(in_line)) .append("\n") .append(partial_size + 2, ' ') - .append("^ matched up to here"); + .append("^ matched up to here") + .move(); auto match_um = lnav::console::user_message::info( attr_line_t("demuxer ") .append_quoted(demux_pair.first) .append(" did not match line ") .append(lnav::roles::number( fmt::to_string(this->mm_line_count)))) - .with_note(note); + .with_note(note) + .move(); this->mm_details.emplace_back(match_um); } if (df.dd_control_pattern.pp_value) { diff --git a/src/field_overlay_source.cc b/src/field_overlay_source.cc index e8d4e1a1..18027ea0 100644 --- a/src/field_overlay_source.cc +++ b/src/field_overlay_source.cc @@ -100,7 +100,8 @@ field_overlay_source::build_field_lines(const listview_curses& lv, line_range{1, 2}, VC_GRAPHIC.value(ACS_LLCORNER))) .with_attr(string_attr( line_range{0, 22}, - VC_ROLE.value(role_t::VCR_INVALID_MSG))); + VC_ROLE.value(role_t::VCR_INVALID_MSG))) + .move(); this->fos_lines.emplace_back(al); } } @@ -419,7 +420,8 @@ field_overlay_source::build_field_lines(const listview_curses& lv, auto qname = lnav::sql::mprintf("%Q", extra_pair.first.c_str()); auto key_line = attr_line_t(" jget(log_raw_text, ") .append(qname.in()) - .append(")"); + .append(")") + .move(); readline_sqlite_highlighter(key_line, std::nullopt); auto key_size = key_line.length(); key_line.append(" = ").append(scrub_ws(extra_pair.second)); @@ -431,8 +433,10 @@ field_overlay_source::build_field_lines(const listview_curses& lv, const auto& jpairs = jpairs_map.second; for (size_t lpc = 0; lpc < jpairs.size(); lpc++) { - auto key_line = attr_line_t(" ").append( - this->fos_log_helper.format_json_getter(jpairs_map.first, lpc)); + auto key_line = attr_line_t(" ") + .append(this->fos_log_helper.format_json_getter( + jpairs_map.first, lpc)) + .move(); readline_sqlite_highlighter(key_line, std::nullopt); auto key_size = key_line.length(); key_line.append(" = ").append(scrub_ws(jpairs[lpc].wt_value)); @@ -452,7 +456,7 @@ field_overlay_source::build_field_lines(const listview_curses& lv, xml_pair.first.second.c_str(), this->fos_log_helper.ldh_file->get_format()->get_name().c_str(), qname.in()); - auto key_line = attr_line_t(" ").append(xp_call.in()); + auto key_line = attr_line_t(" ").append(xp_call.in()).move(); readline_sqlite_highlighter(key_line, std::nullopt); auto key_size = key_line.length(); key_line.append(" = ").append(scrub_ws(xml_pair.second)); @@ -526,8 +530,8 @@ field_overlay_source::build_meta_line(const listview_curses& lv, .append(" to apply them") .append(lv.get_selection() == row ? " to this line" : "") - .with_attr_for_all( - VC_ROLE.value(role_t::VCR_COMMENT)); + .with_attr_for_all(VC_ROLE.value(role_t::VCR_COMMENT)) + .move(); dst.emplace_back(anno_msg); } @@ -545,7 +549,8 @@ field_overlay_source::build_meta_line(const listview_curses& lv, if (!line_meta.bm_opid.empty()) { auto al = attr_line_t() .append(" Op ID: "_table_header) - .append(lnav::roles::identifier(line_meta.bm_opid)); + .append(lnav::roles::identifier(line_meta.bm_opid)) + .move(); dst.emplace_back(al); } diff --git a/src/hotkeys.cc b/src/hotkeys.cc index b2cdd443..24b9b4a2 100644 --- a/src/hotkeys.cc +++ b/src/hotkeys.cc @@ -221,7 +221,8 @@ handle_paging_key(int ch, const char* keyseq) auto al = attr_line_t("mouse mode -- ") .append(mouse_i.is_enabled() ? "enabled"_symbol - : "disabled"_symbol); + : "disabled"_symbol) + .move(); if (mouse_i.is_enabled() && lnav_config.lc_mouse_mode == lnav_mouse_mode::disabled) { diff --git a/src/log_format.cc b/src/log_format.cc index 187111aa..7a2a6688 100644 --- a/src/log_format.cc +++ b/src/log_format.cc @@ -2992,7 +2992,8 @@ external_log_format::build(std::vector& errors) auto sql_al = attr_line_t(hpair.second) .with_attr_for_all(SA_PREFORMATTED.value()) .with_attr_for_all( - VC_ROLE.value(role_t::VCR_QUOTED_CODE)); + VC_ROLE.value(role_t::VCR_QUOTED_CODE)) + .move(); readline_sqlite_highlighter(sql_al, std::nullopt); intern_string_t watch_expr_path = intern_string::lookup( fmt::format(FMT_STRING("/{}/converter/header/expr/{}"), @@ -3004,7 +3005,8 @@ external_log_format::build(std::vector& errors) auto um = lnav::console::user_message::error( "SQL expression is invalid") .with_reason(sqlite3_errmsg(hexprs->e_db.in())) - .with_snippet(snippet); + .with_snippet(snippet) + .move(); errors.emplace_back(um); continue; @@ -3022,7 +3024,8 @@ external_log_format::build(std::vector& errors) .with_help( "The converter command transforms the file " "into a format that can be consumed by lnav") - .with_snippets(this->get_snippets()); + .with_snippets(this->get_snippets()) + .move(); errors.emplace_back(um); } } @@ -3069,7 +3072,8 @@ external_log_format::build(std::vector& errors) = attr_line_t("the following captures are available:\n ") .join(available_captures, VC_ROLE.value(role_t::VCR_SYMBOL), - ", "); + ", ") + .move(); errors.emplace_back( lnav::console::user_message::warning( attr_line_t("invalid value ") @@ -3298,7 +3302,8 @@ external_log_format::build(std::vector& errors) attr_line_t("timestamp was not fully matched: ") .append_quoted(ts_cap.value())) .with_snippet(elf_sample.s_line.to_snippet()) - .with_note(notes); + .with_note(notes) + .move(); errors.emplace_back(um); } @@ -3439,7 +3444,8 @@ external_log_format::build(std::vector& errors) .append_quoted(lnav::roles::symbol( level_names[elf_sample.s_level]))) .with_snippet(elf_sample.s_line.to_snippet()) - .with_note(note_al); + .with_note(note_al) + .move(); if (!this->elf_level_patterns.empty()) { um.with_help( attr_line_t("Level regexes are not anchored to the " diff --git a/src/logfile_sub_source.cc b/src/logfile_sub_source.cc index eb97255a..6d27db9a 100644 --- a/src/logfile_sub_source.cc +++ b/src/logfile_sub_source.cc @@ -2544,7 +2544,8 @@ logfile_sub_source::text_crumbs_for_line(int line, auto key = text_anchors::to_anchor_string(name); auto display = attr_line_t() .append("\u2291 "_symbol) - .append(lnav::roles::variable(name)); + .append(lnav::roles::variable(name)) + .move(); crumbs.emplace_back( key, display, diff --git a/src/vtab_module.hh b/src/vtab_module.hh index 64e7e38a..1278b9c1 100644 --- a/src/vtab_module.hh +++ b/src/vtab_module.hh @@ -87,17 +87,14 @@ struct is_nullable> : std::true_type {}; template struct from_sqlite { - using U = typename std::remove_reference::type; + using U = std::remove_reference_t; - inline U operator()(int argc, sqlite3_value** val, int argi) - { - return U(); - }; + U operator()(int argc, sqlite3_value** val, int argi) { return U(); } }; template<> struct from_sqlite { - inline bool operator()(int argc, sqlite3_value** val, int argi) + bool operator()(int argc, sqlite3_value** val, int argi) { if (sqlite3_value_numeric_type(val[argi]) != SQLITE_INTEGER) { throw from_sqlite_conversion_error("integer", argi); @@ -109,7 +106,7 @@ struct from_sqlite { template<> struct from_sqlite { - inline int64_t operator()(int argc, sqlite3_value** val, int argi) + int64_t operator()(int argc, sqlite3_value** val, int argi) { if (sqlite3_value_numeric_type(val[argi]) != SQLITE_INTEGER) { throw from_sqlite_conversion_error("integer", argi); @@ -121,7 +118,7 @@ struct from_sqlite { template<> struct from_sqlite { - inline sqlite3_value* operator()(int argc, sqlite3_value** val, int argi) + sqlite3_value* operator()(int argc, sqlite3_value** val, int argi) { return val[argi]; } @@ -129,7 +126,7 @@ struct from_sqlite { template<> struct from_sqlite { - inline int operator()(int argc, sqlite3_value** val, int argi) + int operator()(int argc, sqlite3_value** val, int argi) { if (sqlite3_value_numeric_type(val[argi]) != SQLITE_INTEGER) { throw from_sqlite_conversion_error("integer", argi); @@ -141,7 +138,7 @@ struct from_sqlite { template<> struct from_sqlite { - inline const char* operator()(int argc, sqlite3_value** val, int argi) + const char* operator()(int argc, sqlite3_value** val, int argi) { return (const char*) sqlite3_value_text(val[argi]); } @@ -149,9 +146,9 @@ struct from_sqlite { template<> struct from_sqlite { - inline string_fragment operator()(int argc, sqlite3_value** val, int argi) + string_fragment operator()(int argc, sqlite3_value** val, int argi) { - auto ptr = (const char*) sqlite3_value_blob(val[argi]); + const auto ptr = (const char*) sqlite3_value_blob(val[argi]); if (ptr == nullptr) { return string_fragment::invalid(); @@ -162,7 +159,7 @@ struct from_sqlite { template<> struct from_sqlite { - inline std::string operator()(int argc, sqlite3_value** val, int argi) + std::string operator()(int argc, sqlite3_value** val, int argi) { return { (const char*) sqlite3_value_blob(val[argi]), @@ -173,7 +170,7 @@ struct from_sqlite { template<> struct from_sqlite { - inline double operator()(int argc, sqlite3_value** val, int argi) + double operator()(int argc, sqlite3_value** val, int argi) { return sqlite3_value_double(val[argi]); } @@ -181,9 +178,7 @@ struct from_sqlite { template struct from_sqlite> { - inline std::optional operator()(int argc, - sqlite3_value** val, - int argi) + std::optional operator()(int argc, sqlite3_value** val, int argi) { if (argi >= argc || sqlite3_value_type(val[argi]) == SQLITE_NULL) { return std::nullopt; @@ -195,7 +190,7 @@ struct from_sqlite> { template struct from_sqlite&> { - inline std::vector operator()(int argc, sqlite3_value** val, int argi) + std::vector operator()(int argc, sqlite3_value** val, int argi) { std::vector retval; @@ -209,9 +204,7 @@ struct from_sqlite&> { template struct from_sqlite> { - inline vtab_types::nullable operator()(int argc, - sqlite3_value** val, - int argi) + vtab_types::nullable operator()(int argc, sqlite3_value** val, int argi) { return {from_sqlite()(argc, val, argi)}; } @@ -276,12 +269,12 @@ to_sqlite(sqlite3_context* ctx, bool val) } template -inline void -to_sqlite(sqlite3_context* ctx, - T val, - typename std::enable_if::value - && !std::is_same::value>::type* dummy - = 0) +void +to_sqlite( + sqlite3_context* ctx, + T val, + std::enable_if_t && !std::is_same_v>* dummy + = 0) { sqlite3_result_int64(ctx, val); } @@ -295,7 +288,7 @@ to_sqlite(sqlite3_context* ctx, double val) inline void to_sqlite(sqlite3_context* ctx, auto_mem str) { - auto free_func = str.get_free_func(); + const auto free_func = str.get_free_func(); sqlite3_result_text(ctx, str.release(), -1, free_func); } @@ -303,7 +296,7 @@ to_sqlite(sqlite3_context* ctx, auto_mem str) #define FLATTEN_SUBTYPE 0x5f template -inline void +void to_sqlite(sqlite3_context* ctx, std::optional& val) { if (val.has_value()) { @@ -314,7 +307,7 @@ to_sqlite(sqlite3_context* ctx, std::optional& val) } template -inline void +void to_sqlite(sqlite3_context* ctx, std::optional val) { if (val.has_value()) { @@ -469,12 +462,14 @@ struct sqlite_func_adapter { return; } - for (size_t lpc = 0; lpc < REQ_COUNT; lpc++) { - if (!IS_NULLABLE[lpc] && !IS_SQLITE3_VALUE[lpc] - && sqlite3_value_type(argv[lpc]) == SQLITE_NULL) - { - sqlite3_result_null(context); - return; + if constexpr (REQ_COUNT > 0) { + for (size_t lpc = 0; lpc < REQ_COUNT; lpc++) { + if (!IS_NULLABLE[lpc] && !IS_SQLITE3_VALUE[lpc] + && sqlite3_value_type(argv[lpc]) == SQLITE_NULL) + { + sqlite3_result_null(context); + return; + } } }