From 396ea3daf393baab826ee0721a8da8fd07963ec0 Mon Sep 17 00:00:00 2001 From: Alexander Shaduri Date: Fri, 3 Mar 2023 23:00:52 +0400 Subject: [PATCH] Fixed some clang-tidy warnings. --- src/applib/app_pcrecpp.h | 10 +- src/applib/async_command_executor.cpp | 18 +-- src/applib/async_command_executor.h | 2 +- src/applib/command_executor.cpp | 2 +- src/applib/smartctl_ata_text_parser.cpp | 150 ++++++++++++------------ src/applib/smartctl_executor.cpp | 4 +- src/applib/smartctl_executor.h | 2 +- src/applib/storage_detector_win32.cpp | 62 +++++----- src/applib/storage_device.cpp | 12 +- src/gsc_add_device_window.cpp | 4 +- src/gsc_info_window.cpp | 70 +++++------ src/gsc_init.cpp | 26 ++-- src/gsc_main_window_iconview.h | 42 +++---- src/rconfig/autosave.h | 2 +- src/rconfig/loadsave.h | 2 +- 15 files changed, 204 insertions(+), 204 deletions(-) diff --git a/src/applib/app_pcrecpp.h b/src/applib/app_pcrecpp.h index 25897be..a3f7ddc 100644 --- a/src/applib/app_pcrecpp.h +++ b/src/applib/app_pcrecpp.h @@ -185,7 +185,7 @@ pcrecpp::RE_Options app_pcre_get_options(std::string_view modifiers) pcrecpp::RE_Options options; #endif - for (char c : modifiers) { + for (const char c : modifiers) { switch (c) { // Note: Most of these are from pcretest man page. // Perl lacks some of them. @@ -212,15 +212,15 @@ pcrecpp::RE app_pcre_re(const std::string& perl_pattern) if (perl_pattern.size() >= 2 && perl_pattern[0] == '/') { // find the separator - std::string::size_type endpos = perl_pattern.rfind('/'); + const std::string::size_type endpos = perl_pattern.rfind('/'); DBG_ASSERT(endpos != std::string::npos); // shouldn't happen // no need to unescape slashes in pattern - pcre seems to not mind. - return pcrecpp::RE(perl_pattern.substr(1, endpos - 1), - app_pcre_get_options(perl_pattern.substr(endpos + 1))); + return {perl_pattern.substr(1, endpos - 1), + app_pcre_get_options(perl_pattern.substr(endpos + 1))}; } - return pcrecpp::RE(perl_pattern, app_pcre_get_options({})); + return {perl_pattern, app_pcre_get_options({})}; } diff --git a/src/applib/async_command_executor.cpp b/src/applib/async_command_executor.cpp index ac197b7..b46c077 100644 --- a/src/applib/async_command_executor.cpp +++ b/src/applib/async_command_executor.cpp @@ -132,7 +132,7 @@ bool AsyncCommandExecutor::execute() str_stderr_.clear(); - std::string cmd = command_exec_ + " " + command_args_; + const std::string cmd = command_exec_ + " " + command_args_; // Make command vector @@ -161,7 +161,7 @@ bool AsyncCommandExecutor::execute() if (change_lang) { child_env.reset(g_environ_setenv(child_env.release(), "LC_ALL", "C", TRUE)); } - std::vector envp = Glib::ArrayHandler::array_to_vector(child_env.release(), + const std::vector envp = Glib::ArrayHandler::array_to_vector(child_env.release(), Glib::OWNERSHIP_DEEP); // Set the current directory to application directory so CWD does not interfere with finding binaries. @@ -215,7 +215,7 @@ bool AsyncCommandExecutor::execute() // If using locales, call g_locale_to_utf8() or g_convert() afterwards. // blocking writes if the pipe is full helps for small-pipe systems (see man 7 pipe). - int channel_flags = ~G_IO_FLAG_NONBLOCK; + const int channel_flags = ~G_IO_FLAG_NONBLOCK; // Note about GError's here: // What do we do? The command is already running, so let's ignore these @@ -239,7 +239,7 @@ bool AsyncCommandExecutor::execute() auto cond = GIOCondition(G_IO_IN | G_IO_PRI | G_IO_HUP | G_IO_ERR | G_IO_NVAL); // Channel reader callback must be called before other stuff so that the loss is minimal. - gint io_priority = G_PRIORITY_HIGH; + const int io_priority = G_PRIORITY_HIGH; this->event_source_id_stdout_ = g_io_add_watch_full(channel_stdout_, io_priority, cond, &cmdex_on_channel_io_stdout, this, nullptr); @@ -349,18 +349,18 @@ void AsyncCommandExecutor::stopped_cleanup() // various statuses (see waitpid (2)): if (WIFEXITED(waitpid_status_)) { // exited normally - int exit_status = WEXITSTATUS(waitpid_status_); + const int exit_status = WEXITSTATUS(waitpid_status_); if (exit_status != 0) { // translate the exit_code into a message - std::string msg = (translator_func_ ? translator_func_(exit_status) + const std::string msg = (translator_func_ ? translator_func_(exit_status) : "[no translator function, exit code: " + std::to_string(exit_status)); push_error(Error("exit", ErrorLevel::warn, exit_status, msg)); } } else { if (WIFSIGNALED(waitpid_status_)) { // exited by signal - int sig_num = WTERMSIG(waitpid_status_); + const int sig_num = WTERMSIG(waitpid_status_); // If it's not our signal, treat as error. // Note: they will never match under win32 @@ -473,7 +473,7 @@ gboolean AsyncCommandExecutor::on_channel_io(GIOChannel* channel, do { GError* channel_error = nullptr; gsize bytes_read = 0; - GIOStatus status = g_io_channel_read_chars(channel, buf.data(), count, &bytes_read, &channel_error); + const GIOStatus status = g_io_channel_read_chars(channel, buf.data(), count, &bytes_read, &channel_error); if (bytes_read != 0) output_str->append(buf.data(), bytes_read); @@ -498,7 +498,7 @@ gboolean AsyncCommandExecutor::on_channel_io(GIOChannel* channel, -bool AsyncCommandExecutor::stopped_cleanup_needed() +bool AsyncCommandExecutor::stopped_cleanup_needed() const { return (child_watch_handler_called_); } diff --git a/src/applib/async_command_executor.h b/src/applib/async_command_executor.h index 141b717..fdefe65 100644 --- a/src/applib/async_command_executor.h +++ b/src/applib/async_command_executor.h @@ -94,7 +94,7 @@ class AsyncCommandExecutor : public hz::ErrorHolder { /// Returns true if command has stopped. /// Call repeatedly in a waiting function, after execute(). /// When it returns true, call stopped_cleanup(). - bool stopped_cleanup_needed(); + bool stopped_cleanup_needed() const; /// Check if the process is running. Note that if this returns false, it doesn't mean that diff --git a/src/applib/command_executor.cpp b/src/applib/command_executor.cpp index f503b5a..c1c2e94 100644 --- a/src/applib/command_executor.cpp +++ b/src/applib/command_executor.cpp @@ -70,7 +70,7 @@ bool CommandExecutor::execute() { set_error_msg(""); // clear old error if present - bool slot_connected = !(signal_execute_tick().slots().begin() == signal_execute_tick().slots().end()); + const bool slot_connected = !(signal_execute_tick().slots().begin() == signal_execute_tick().slots().end()); if (slot_connected && !signal_execute_tick().emit(TickStatus::starting)) return false; diff --git a/src/applib/smartctl_ata_text_parser.cpp b/src/applib/smartctl_ata_text_parser.cpp index da78bef..3ef0da7 100644 --- a/src/applib/smartctl_ata_text_parser.cpp +++ b/src/applib/smartctl_ata_text_parser.cpp @@ -97,7 +97,7 @@ bool SmartctlAtaTextParser::parse_full(const std::string& full) // Checksum warnings are kind of randomly distributed, so // extract and remove them. { - pcrecpp::RE re = app_pcre_re("/\\nWarning! SMART (.+) Structure error: invalid SMART checksum\\.$/mi"); + const pcrecpp::RE re = app_pcre_re("/\\nWarning! SMART (.+) Structure error: invalid SMART checksum\\.$/mi"); std::string name; pcrecpp::StringPiece input(s); // position tracker @@ -121,7 +121,7 @@ bool SmartctlAtaTextParser::parse_full(const std::string& full) // The Warning: parts also screw up newlines sometimes (making double-newlines, // confusing for section separation). { - pcrecpp::RE re = app_pcre_re("/^(Warning: ATA error count.*\\n)\\n/mi"); + const pcrecpp::RE re = app_pcre_re("/^(Warning: ATA error count.*\\n)\\n/mi"); std::string match; if (app_pcre_match(re, s, &match)) { @@ -133,10 +133,10 @@ bool SmartctlAtaTextParser::parse_full(const std::string& full) // If the device doesn't support many things, the warnings aren't separated (for sections). // Fix that. This affects old smartctl only (at least 6.5 fixed the warnings). { - pcrecpp::RE re1 = app_pcre_re("/^(Warning: device does not support Error Logging)$/mi"); - pcrecpp::RE re2 = app_pcre_re("/^(Warning: device does not support Self Test Logging)$/mi"); - pcrecpp::RE re3 = app_pcre_re("/^(Device does not support Selective Self Tests\\/Logging)$/mi"); - pcrecpp::RE re4 = app_pcre_re("/^(Warning: device does not support SCT Commands)$/mi"); + const pcrecpp::RE re1 = app_pcre_re("/^(Warning: device does not support Error Logging)$/mi"); + const pcrecpp::RE re2 = app_pcre_re("/^(Warning: device does not support Self Test Logging)$/mi"); + const pcrecpp::RE re3 = app_pcre_re("/^(Device does not support Selective Self Tests\\/Logging)$/mi"); + const pcrecpp::RE re4 = app_pcre_re("/^(Warning: device does not support SCT Commands)$/mi"); std::string match; if (app_pcre_match(re1, s, &match)) @@ -157,23 +157,23 @@ bool SmartctlAtaTextParser::parse_full(const std::string& full) // "ATA_READ_LOG_EXT (addr=0x00:0x00, page=0, n=1) failed: 48-bit ATA commands not implemented" // or "ATA_READ_LOG_EXT (addr=0x11:0x00, page=0, n=1) failed: scsi error aborted command" // in front of "Read GP Log Directory failed" and "Read SATA Phy Event Counters failed". - pcrecpp::RE re1 = app_pcre_re("/^(ATA_READ_LOG_EXT \\([^)]+\\) failed: .*)$/mi"); + const pcrecpp::RE re1 = app_pcre_re("/^(ATA_READ_LOG_EXT \\([^)]+\\) failed: .*)$/mi"); // "SMART WRITE LOG does not return COUNT and LBA_LOW register" // in front of "SCT (Get) Error Recovery Control command failed" (scterc section) - pcrecpp::RE re2= app_pcre_re("/^((?:Error )?SMART WRITE LOG does not return COUNT and LBA_LOW register)$/mi"); + const pcrecpp::RE re2= app_pcre_re("/^((?:Error )?SMART WRITE LOG does not return COUNT and LBA_LOW register)$/mi"); // "Read SCT Status failed: scsi error aborted command" // in front of "Read SCT Temperature History failed" and "SCT (Get) Error Recovery Control command failed" - pcrecpp::RE re3= app_pcre_re("/^(Read SCT Status failed: .*)$/mi"); + const pcrecpp::RE re3= app_pcre_re("/^(Read SCT Status failed: .*)$/mi"); // "Unknown SCT Status format version 0, should be 2 or 3." - pcrecpp::RE re4= app_pcre_re("/^(Unknown SCT Status format version .*)$/mi"); + const pcrecpp::RE re4= app_pcre_re("/^(Unknown SCT Status format version .*)$/mi"); // "Read SCT Data Table failed: scsi error aborted command" - pcrecpp::RE re5= app_pcre_re("/^(Read SCT Data Table failed: .*)$/mi"); + const pcrecpp::RE re5= app_pcre_re("/^(Read SCT Data Table failed: .*)$/mi"); // "Write SCT Data Table failed: Undefined error: 0" // in front of "Read SCT Temperature History failed" - pcrecpp::RE re6= app_pcre_re("/^(Write SCT Data Table failed: .*)$/mi"); + const pcrecpp::RE re6= app_pcre_re("/^(Write SCT Data Table failed: .*)$/mi"); // "Unexpected SCT status 0x0000 (action_code=0, function_code=0)" // in front of "Read SCT Temperature History failed" - pcrecpp::RE re7= app_pcre_re("/^(Unexpected SCT status .*\\))$/mi"); + const pcrecpp::RE re7= app_pcre_re("/^(Unexpected SCT status .*\\))$/mi"); std::string match; if (app_pcre_match(re1, s, &match)) @@ -247,7 +247,7 @@ bool SmartctlAtaTextParser::parse_full(const std::string& full) tmp_pos = s.find('\n', section_start_pos); // works with \r\n too. This may be npos if nothing follows the header. // trim is needed to remove potential \r in the end - std::string section_header = hz::string_trim_copy(s.substr(section_start_pos, + const std::string section_header = hz::string_trim_copy(s.substr(section_start_pos, (tmp_pos == std::string::npos ? tmp_pos : (tmp_pos - section_start_pos)) )); std::string section_body_str; @@ -322,7 +322,7 @@ bool SmartctlAtaTextParser::parse_section_info(const std::string& body) // split by lines. // e.g. Device Model: ST3500630AS - pcrecpp::RE re = app_pcre_re("/^([^\\n]+): [ \\t]*(.*)$/miU"); // ungreedy + const pcrecpp::RE re = app_pcre_re("/^([^\\n]+): [ \\t]*(.*)$/miU"); // ungreedy std::vector lines; hz::string_split(body, '\n', lines, false); @@ -476,7 +476,7 @@ bool SmartctlAtaTextParser::parse_section_info_property(AtaStorageProperty& p) } else if (app_pcre_match("/^User Capacity$/mi", p.reported_name)) { p.set_name(p.reported_name, "user_capacity/bytes", "Capacity"); int64_t v = 0; - if ((p.readable_value = SmartctlTextParserHelper::parse_byte_size(p.reported_value, v, true)).empty()) { + if (p.readable_value = SmartctlTextParserHelper::parse_byte_size(p.reported_value, v, true); p.empty()) { p.readable_value = "[unknown]"; } else { p.value = v; // integer-type value @@ -889,12 +889,12 @@ SCT capabilities: (0x003d) SCT Status supported. // parse each block - pcrecpp::RE re = app_pcre_re(R"(/([^:]*):\s*\(([^)]+)\)\s*(.*)/ms)"); + const pcrecpp::RE re = app_pcre_re(R"(/([^:]*):\s*\(([^)]+)\)\s*(.*)/ms)"); bool cap_found = false; // found at least one capability for(std::size_t i = 0; i < blocks.size(); ++i) { - std::string block = hz::string_trim_copy(blocks[i]); + const std::string block = hz::string_trim_copy(blocks[i]); std::string name_orig, numvalue_orig, strvalue_orig; @@ -908,10 +908,10 @@ SCT capabilities: (0x003d) SCT Status supported. } // flatten: - std::string name = hz::string_trim_copy(hz::string_remove_adjacent_duplicates_copy( + const std::string name = hz::string_trim_copy(hz::string_remove_adjacent_duplicates_copy( hz::string_replace_chars_copy(name_orig, "\t\n", ' '), ' ')); - std::string strvalue = hz::string_trim_copy(hz::string_remove_adjacent_duplicates_copy( + const std::string strvalue = hz::string_trim_copy(hz::string_remove_adjacent_duplicates_copy( hz::string_replace_chars_copy(strvalue_orig, "\t\n", ' '), ' ')); int64_t numvalue = -1; @@ -1000,36 +1000,36 @@ bool SmartctlAtaTextParser::parse_section_data_internal_capabilities(AtaStorageP // "was never started", "was completed without error", "is in progress", // "was suspended by an interrupting command from host", etc... - pcrecpp::RE re_offline_status = app_pcre_re("/^(Off-?line data collection) activity (?:is|was) (.*)$/mi"); + const pcrecpp::RE re_offline_status = app_pcre_re("/^(Off-?line data collection) activity (?:is|was) (.*)$/mi"); // "Enabled", "Disabled". May not show up on older smartctl (< 5.1.10), so no way of knowing there. - pcrecpp::RE re_offline_enabled = app_pcre_re("/^(Auto Off-?line Data Collection):[ \\t]*(.*)$/mi"); - pcrecpp::RE re_offline_immediate = app_pcre_re("/^(SMART execute Off-?line immediate)$/mi"); + const pcrecpp::RE re_offline_enabled = app_pcre_re("/^(Auto Off-?line Data Collection):[ \\t]*(.*)$/mi"); + const pcrecpp::RE re_offline_immediate = app_pcre_re("/^(SMART execute Off-?line immediate)$/mi"); // "No Auto Offline data collection support.", "Auto Offline data collection on/off support.". - pcrecpp::RE re_offline_auto = app_pcre_re("/^(No |)(Auto Off-?line data collection (?:on\\/off )?support)$/mi"); + const pcrecpp::RE re_offline_auto = app_pcre_re("/^(No |)(Auto Off-?line data collection (?:on\\/off )?support)$/mi"); // Same as above (smartctl <= 5.1-18). "No Automatic timer ON/OFF support." - pcrecpp::RE re_offline_auto2 = app_pcre_re("/^(No |)(Automatic timer ON\\/OFF support)$/mi"); - pcrecpp::RE re_offline_suspend = app_pcre_re("/^(?:Suspend|Abort) (Off-?line collection upon new command)$/mi"); - pcrecpp::RE re_offline_surface = app_pcre_re("/^(No |)(Off-?line surface scan supported)$/mi"); + const pcrecpp::RE re_offline_auto2 = app_pcre_re("/^(No |)(Automatic timer ON\\/OFF support)$/mi"); + const pcrecpp::RE re_offline_suspend = app_pcre_re("/^(?:Suspend|Abort) (Off-?line collection upon new command)$/mi"); + const pcrecpp::RE re_offline_surface = app_pcre_re("/^(No |)(Off-?line surface scan supported)$/mi"); - pcrecpp::RE re_selftest_support = app_pcre_re("/^(No |)(Self-test supported)$/mi"); - pcrecpp::RE re_conv_selftest_support = app_pcre_re("/^(No |)(Conveyance Self-test supported)$/mi"); - pcrecpp::RE re_selective_selftest_support = app_pcre_re("/^(No |)(Selective Self-test supported)$/mi"); + const pcrecpp::RE re_selftest_support = app_pcre_re("/^(No |)(Self-test supported)$/mi"); + const pcrecpp::RE re_conv_selftest_support = app_pcre_re("/^(No |)(Conveyance Self-test supported)$/mi"); + const pcrecpp::RE re_selective_selftest_support = app_pcre_re("/^(No |)(Selective Self-test supported)$/mi"); - pcrecpp::RE re_sct_status = app_pcre_re("/^(SCT Status supported)$/mi"); - pcrecpp::RE re_sct_control = app_pcre_re("/^(SCT Feature Control supported)$/mi"); // means can change logging interval - pcrecpp::RE re_sct_data = app_pcre_re("/^(SCT Data Table supported)$/mi"); + const pcrecpp::RE re_sct_status = app_pcre_re("/^(SCT Status supported)$/mi"); + const pcrecpp::RE re_sct_control = app_pcre_re("/^(SCT Feature Control supported)$/mi"); // means can change logging interval + const pcrecpp::RE re_sct_data = app_pcre_re("/^(SCT Data Table supported)$/mi"); // these are matched on name - pcrecpp::RE re_offline_status_group = app_pcre_re("/^(Off-?line data collection status)/mi"); - pcrecpp::RE re_offline_time = app_pcre_re("/^(Total time to complete Off-?line data collection)/mi"); - pcrecpp::RE re_offline_cap_group = app_pcre_re("/^(Off-?line data collection capabilities)/mi"); - pcrecpp::RE re_smart_cap_group = app_pcre_re("/^(SMART capabilities)/mi"); - pcrecpp::RE re_error_log_cap_group = app_pcre_re("/^(Error logging capability)/mi"); - pcrecpp::RE re_sct_cap_group = app_pcre_re("/^(SCT capabilities)/mi"); - pcrecpp::RE re_selftest_status = app_pcre_re("/^Self-test execution status/mi"); - pcrecpp::RE re_selftest_short_time = app_pcre_re("/^(Short self-test routine recommended polling time)/mi"); - pcrecpp::RE re_selftest_long_time = app_pcre_re("/^(Extended self-test routine recommended polling time)/mi"); - pcrecpp::RE re_conv_selftest_time = app_pcre_re("/^(Conveyance self-test routine recommended polling time)/mi"); + const pcrecpp::RE re_offline_status_group = app_pcre_re("/^(Off-?line data collection status)/mi"); + const pcrecpp::RE re_offline_time = app_pcre_re("/^(Total time to complete Off-?line data collection)/mi"); + const pcrecpp::RE re_offline_cap_group = app_pcre_re("/^(Off-?line data collection capabilities)/mi"); + const pcrecpp::RE re_smart_cap_group = app_pcre_re("/^(SMART capabilities)/mi"); + const pcrecpp::RE re_error_log_cap_group = app_pcre_re("/^(Error logging capability)/mi"); + const pcrecpp::RE re_sct_cap_group = app_pcre_re("/^(SCT capabilities)/mi"); + const pcrecpp::RE re_selftest_status = app_pcre_re("/^Self-test execution status/mi"); + const pcrecpp::RE re_selftest_short_time = app_pcre_re("/^(Short self-test routine recommended polling time)/mi"); + const pcrecpp::RE re_selftest_long_time = app_pcre_re("/^(Extended self-test routine recommended polling time)/mi"); + const pcrecpp::RE re_conv_selftest_time = app_pcre_re("/^(Conveyance self-test routine recommended polling time)/mi"); if (cap_prop.section != AtaStorageProperty::Section::data || cap_prop.subsection != AtaStorageProperty::SubSection::capabilities) { debug_out_error("app", DBG_FUNC_MSG << "Non-capability property passed.\n"); @@ -1297,26 +1297,26 @@ ID# ATTRIBUTE_NAME FLAGS VALUE WORST THRESH FAIL RAW_VALUE bool attr_found = false; // at least one attribute was found int attr_format_style = FormatStyleOld; - std::string space_re = "[ \\t]+"; + const std::string space_re = "[ \\t]+"; - std::string old_flag_re = "(0x[a-fA-F0-9]+)"; - std::string brief_flag_re = "([A-Z+-]{2,})"; + const std::string old_flag_re = "(0x[a-fA-F0-9]+)"; + const std::string brief_flag_re = "([A-Z+-]{2,})"; // We allow name with spaces only in the old format, not in brief. // This has to do with the name end detection - it's either 0x (flag's start) in the old format, // or a space in the brief format. - std::string old_base_re = R"([ \t]*([0-9]+) ([^ \t\n]+(?:[^0-9\t\n]+)*))" + space_re + old_flag_re + space_re; // ID / name / flag - std::string brief_base_re = R"([ \t]*([0-9]+) ([^ \t\n]+))" + space_re + brief_flag_re + space_re; // ID / name / flag - std::string vals_re = "([0-9-]+)" + space_re + "([0-9-]+)" + space_re + "([0-9-]+)" + space_re; // value / worst / threshold - std::string type_re = "([^ \\t\\n]+)" + space_re; - std::string updated_re = "([^ \\t\\n]+)" + space_re; - std::string failed_re = "([^ \\t\\n]+)" + space_re; - std::string raw_re = "(.+)[ \\t]*"; + const std::string old_base_re = R"([ \t]*([0-9]+) ([^ \t\n]+(?:[^0-9\t\n]+)*))" + space_re + old_flag_re + space_re; // ID / name / flag + const std::string brief_base_re = R"([ \t]*([0-9]+) ([^ \t\n]+))" + space_re + brief_flag_re + space_re; // ID / name / flag + const std::string vals_re = "([0-9-]+)" + space_re + "([0-9-]+)" + space_re + "([0-9-]+)" + space_re; // value / worst / threshold + const std::string type_re = "([^ \\t\\n]+)" + space_re; + const std::string updated_re = "([^ \\t\\n]+)" + space_re; + const std::string failed_re = "([^ \\t\\n]+)" + space_re; + const std::string raw_re = "(.+)[ \\t]*"; - pcrecpp::RE re_old_up = app_pcre_re("/" + old_base_re + vals_re + type_re + updated_re + failed_re + raw_re + "/mi"); - pcrecpp::RE re_old_noup = app_pcre_re("/" + old_base_re + vals_re + type_re + failed_re + raw_re + "/mi"); - pcrecpp::RE re_brief = app_pcre_re("/" + brief_base_re + vals_re + failed_re + raw_re + "/mi"); + const pcrecpp::RE re_old_up = app_pcre_re("/" + old_base_re + vals_re + type_re + updated_re + failed_re + raw_re + "/mi"); + const pcrecpp::RE re_old_noup = app_pcre_re("/" + old_base_re + vals_re + type_re + failed_re + raw_re + "/mi"); + const pcrecpp::RE re_brief = app_pcre_re("/" + brief_base_re + vals_re + failed_re + raw_re + "/mi"); - pcrecpp::RE re_flag_descr = app_pcre_re("/^[\\t ]+\\|/mi"); + const pcrecpp::RE re_flag_descr = app_pcre_re("/^[\\t ]+\\|/mi"); for (const auto& line : lines) { @@ -1339,7 +1339,7 @@ ID# ATTRIBUTE_NAME FLAGS VALUE WORST THRESH FAIL RAW_VALUE } if (app_pcre_match("/Data Structure revision number/mi", line)) { - pcrecpp::RE re = app_pcre_re("/^([^:\\n]+):[ \\t]*(.*)$/mi"); + const pcrecpp::RE re = app_pcre_re("/^([^:\\n]+):[ \\t]*(.*)$/mi"); std::string name, value; if (re.PartialMatch(line, &name, &value)) { hz::string_trim(name); @@ -1570,7 +1570,7 @@ Error 1 [0] occurred at disk power-on lifetime: 1 hours (0 days + 1 hours) { // "SMART Error Log Version: 1" // "SMART Extended Comprehensive Error Log Version: 1 (1 sectors)" - pcrecpp::RE re = app_pcre_re("/^(SMART (Extended Comprehensive )?Error Log Version): ([0-9]+).*?$/mi"); + const pcrecpp::RE re = app_pcre_re("/^(SMART (Extended Comprehensive )?Error Log Version): ([0-9]+).*?$/mi"); std::string name, value; if (re.PartialMatch(sub, &name, &value)) { @@ -1594,7 +1594,7 @@ Error 1 [0] occurred at disk power-on lifetime: 1 hours (0 days + 1 hours) // Error log support { - pcrecpp::RE re = app_pcre_re("/^(Warning: device does not support Error Logging)|(SMART Error Log not supported)$/mi"); + const pcrecpp::RE re = app_pcre_re("/^(Warning: device does not support Error Logging)|(SMART Error Log not supported)$/mi"); if (re.PartialMatch(sub)) { AtaStorageProperty p(pt); @@ -1608,8 +1608,8 @@ Error 1 [0] occurred at disk power-on lifetime: 1 hours (0 days + 1 hours) // Error log entry count { // note: these represent the same information - pcrecpp::RE re1 = app_pcre_re("/^(?:ATA|Device) Error Count:[ \\t]*([0-9]+)/mi"); - pcrecpp::RE re2 = app_pcre_re("/^No Errors Logged$/mi"); + const pcrecpp::RE re1 = app_pcre_re("/^(?:ATA|Device) Error Count:[ \\t]*([0-9]+)/mi"); + const pcrecpp::RE re2 = app_pcre_re("/^No Errors Logged$/mi"); std::string value; if (re1.PartialMatch(sub, &value) || re2.PartialMatch(sub)) { @@ -1637,16 +1637,16 @@ Error 1 [0] occurred at disk power-on lifetime: 1 hours (0 days + 1 hours) // Split by blocks: // "Error 1 [0] occurred at disk power-on lifetime: 1 hours (0 days + 1 hours)" // "Error 25 occurred at disk power-on lifetime: 14799 hours" - pcrecpp::RE re_block = app_pcre_re( + const pcrecpp::RE re_block = app_pcre_re( R"(/^((Error[ \t]*([0-9]+))[ \t]*(?:\[[0-9]+\][ \t])?occurred at disk power-on lifetime:[ \t]*([0-9]+) hours(?:[^\n]*)?.*(?:\n(?: |\n ).*)*)/mi)"); // " When the command that caused the error occurred, the device was active or idle." // Note: For "in an unknown state" - remove first two words. - pcrecpp::RE re_state = app_pcre_re(R"(/occurred, the device was[ \t]*(?: in)?(?: an?)?[ \t]+([^.\n]*)\.?/mi)"); + const pcrecpp::RE re_state = app_pcre_re(R"(/occurred, the device was[ \t]*(?: in)?(?: an?)?[ \t]+([^.\n]*)\.?/mi)"); // " 84 51 2c 71 cd 3f e6 Error: ICRC, ABRT 44 sectors at LBA = 0x063fcd71 = 104844657" // " 40 51 00 f5 41 61 e0 Error: UNC at LBA = 0x006141f5 = 6373877" // " 02 -- 51 00 00 00 00 00 00 00 00 00 00 Error: TK0NF" - pcrecpp::RE re_type = app_pcre_re(R"(/[ \t]+Error:[ \t]*([ ,a-z0-9]+)(?:[ \t]+((?:[0-9]+|at )[ \t]*.*))?$/mi)"); + const pcrecpp::RE re_type = app_pcre_re(R"(/[ \t]+Error:[ \t]*([ ,a-z0-9]+)(?:[ \t]+((?:[0-9]+|at )[ \t]*.*))?$/mi)"); std::string block, name, value_num, value_time; pcrecpp::StringPiece input(sub); // position tracker @@ -1749,7 +1749,7 @@ Num Test_Description Status Remaining LifeTime(hours) LBA // Self-test log support { - pcrecpp::RE re = app_pcre_re("/^(Warning: device does not support Self Test Logging)|(SMART Self-test Log not supported)$/mi"); + const pcrecpp::RE re = app_pcre_re("/^(Warning: device does not support Self Test Logging)|(SMART Self-test Log not supported)$/mi"); if (re.PartialMatch(sub)) { AtaStorageProperty p(pt); @@ -1766,10 +1766,10 @@ Num Test_Description Status Remaining LifeTime(hours) LBA { // SMART Self-test log structure revision number 1 // SMART Extended Self-test Log Version: 1 (1 sectors) - pcrecpp::RE re1 = app_pcre_re(R"(/(SMART Self-test log structure[^\n0-9]*)([^ \n]+)[ \t]*$/mi)"); - pcrecpp::RE re1_ex = app_pcre_re("/(SMART Extended Self-test Log Version: ([0-9]+).*$/mi"); + const pcrecpp::RE re1 = app_pcre_re(R"(/(SMART Self-test log structure[^\n0-9]*)([^ \n]+)[ \t]*$/mi)"); + const pcrecpp::RE re1_ex = app_pcre_re("/(SMART Extended Self-test Log Version: ([0-9]+).*$/mi"); // older smartctl (pre 5.1-16) - pcrecpp::RE re2 = app_pcre_re(R"(/(SMART Self-test log, version number[^\n0-9]*)([^ \n]+)[ \t]*$/mi)"); + const pcrecpp::RE re2 = app_pcre_re(R"(/(SMART Self-test log, version number[^\n0-9]*)([^ \n]+)[ \t]*$/mi)"); std::string name, value; if (re1.PartialMatch(sub, &name, &value) || re1_ex.PartialMatch(sub, &name, &value) || re2.PartialMatch(sub, &name, &value)) { @@ -1796,7 +1796,7 @@ Num Test_Description Status Remaining LifeTime(hours) LBA { // split by columns. // num, type, status, remaining, hours, lba (optional). - pcrecpp::RE re = app_pcre_re( + const pcrecpp::RE re = app_pcre_re( R"(/^(#[ \t]*([0-9]+)[ \t]+(\S+(?: \S+)*) [ \t]*(\S.*) [ \t]*([0-9]+%) [ \t]*([0-9]+)[ \t]*((?: [ \t]*\S.*)?))$/mi)"); std::string line, num, type, status_str, remaining, hours, lba; @@ -2141,17 +2141,17 @@ Page Offset Size Value Description std::vector lines; hz::string_split(sub, '\n', lines, true); - std::string space_re = "[ \\t]+"; + const std::string space_re = "[ \\t]+"; - std::string flag_re = "([A-Z=-]{3,})"; + const std::string flag_re = "([A-Z=-]{3,})"; // Page Offset Size Value Flags Description - pcrecpp::RE line_re = app_pcre_re("/[ \\t]*([0-9a-z]+)" + space_re + "([0-9a-z=]+)" + space_re + "([0-9=]+)" + const pcrecpp::RE line_re = app_pcre_re("/[ \\t]*([0-9a-z]+)" + space_re + "([0-9a-z=]+)" + space_re + "([0-9=]+)" + space_re + "([0-9=-]+)" + space_re + flag_re + space_re + "(.+)/mi"); // Page Offset Size Value Description - pcrecpp::RE line_re_noflags = app_pcre_re("/[ \\t]*([0-9a-z]+)" + space_re + "([0-9a-z=]+)" + space_re + "([0-9=]+)" + const pcrecpp::RE line_re_noflags = app_pcre_re("/[ \\t]*([0-9a-z]+)" + space_re + "([0-9a-z=]+)" + space_re + "([0-9=]+)" + space_re + "([0-9=~-]+)" + space_re + "(.+)/mi"); // flag description lines - pcrecpp::RE re_flag_descr = app_pcre_re("/^[\\t ]+\\|/mi"); + const pcrecpp::RE re_flag_descr = app_pcre_re("/^[\\t ]+\\|/mi"); int devstat_format_style = FormatStyleCurrent; diff --git a/src/applib/smartctl_executor.cpp b/src/applib/smartctl_executor.cpp index 4c909ce..c2528b4 100644 --- a/src/applib/smartctl_executor.cpp +++ b/src/applib/smartctl_executor.cpp @@ -28,7 +28,7 @@ hz::fs::path get_smartctl_binary() // Look in smartmontools installation directory. hz::fs::path system_binary; do { - bool use_smt = rconfig::get_data("system/win32_search_smartctl_in_smartmontools"); + const bool use_smt = rconfig::get_data("system/win32_search_smartctl_in_smartmontools"); if (!use_smt) break; @@ -86,7 +86,7 @@ std::string execute_smartctl(const std::string& device, const std::string& devic { // win32 doesn't have slashes in devices names. For others, check that slash is present. if constexpr(!BuildEnv::is_kernel_family_windows()) { - std::string::size_type pos = device.rfind('/'); // find basename + const std::string::size_type pos = device.rfind('/'); // find basename if (pos == std::string::npos) { debug_out_error("app", DBG_FUNC_MSG << "Invalid device name \"" << device << "\".\n"); return _("Invalid device name specified."); diff --git a/src/applib/smartctl_executor.h b/src/applib/smartctl_executor.h index 7ccc305..e8d173e 100644 --- a/src/applib/smartctl_executor.h +++ b/src/applib/smartctl_executor.h @@ -127,7 +127,7 @@ class SmartctlExecutorGeneric : public ExecutorSync { return; // import the error only if it's relevant. - std::string error_type = e->get_type(); + const std::string error_type = e->get_type(); // accept all errors by default, except: // Treat most exit codes as non-errors. diff --git a/src/applib/storage_detector_win32.cpp b/src/applib/storage_detector_win32.cpp index b590c01..3fa8664 100644 --- a/src/applib/storage_detector_win32.cpp +++ b/src/applib/storage_detector_win32.cpp @@ -215,7 +215,7 @@ std::string get_scan_open_multiport_devices(std::vector& drive } // any_to_unix is needed for windows - std::string output = hz::string_trim_copy(hz::string_any_to_unix_copy(smartctl_ex->get_stdout_str())); + const std::string output = hz::string_trim_copy(hz::string_any_to_unix_copy(smartctl_ex->get_stdout_str())); if (output.empty()) { debug_out_error("app", DBG_FUNC_MSG << "Smartctl returned an empty output.\n"); return _("Smartctl returned an empty output."); @@ -251,7 +251,7 @@ std::string get_scan_open_multiport_devices(std::vector& drive equivalent_pds.insert(drive_num); } - std::string full_dev = dev + "," + port_str; + const std::string full_dev = dev + "," + port_str; auto drive = std::make_shared(full_dev, type); std::map letters_volnames; @@ -405,9 +405,9 @@ inline std::string areca_cli_get_drives(const std::string& cli_binary, const std Enc }; - pcrecpp::RE noenc1_header_re = app_pcre_re("/^\\s*#\\s+Ch#/mi"); - pcrecpp::RE noenc2_header_re = app_pcre_re("/^\\s*#\\s+ModelName/mi"); - pcrecpp::RE exp_header_re = app_pcre_re("/^\\s*#\\s+Enc#/mi"); + const pcrecpp::RE noenc1_header_re = app_pcre_re("/^\\s*#\\s+Ch#/mi"); + const pcrecpp::RE noenc2_header_re = app_pcre_re("/^\\s*#\\s+ModelName/mi"); + const pcrecpp::RE exp_header_re = app_pcre_re("/^\\s*#\\s+Enc#/mi"); FormatType format_type = FormatType::Unknown; for (const auto& line : lines) { @@ -430,11 +430,11 @@ inline std::string areca_cli_get_drives(const std::string& cli_binary, const std } // Note: These may not match the full model, but just the first part is sufficient for comparison with "N.A.". - pcrecpp::RE noexp1_port_re = app_pcre_re("/^\\s*[0-9]+\\s+([0-9]+)\\s+([^\\s]+)/mi"); // matches port, model. - pcrecpp::RE noexp2_port_re = app_pcre_re("/^\\s*([0-9]+)\\s+([^\\s]+)/mi"); // matches port, model. - pcrecpp::RE exp_port_re = app_pcre_re("/^\\s*[0-9]+\\s+([0-9]+)\\s+(?:Slot#|SLOT\\s+)([0-9]+)\\s+([^\\s]+)/mi"); // matches enclosure, port, model. + const pcrecpp::RE noexp1_port_re = app_pcre_re("/^\\s*[0-9]+\\s+([0-9]+)\\s+([^\\s]+)/mi"); // matches port, model. + const pcrecpp::RE noexp2_port_re = app_pcre_re("/^\\s*([0-9]+)\\s+([^\\s]+)/mi"); // matches port, model. + const pcrecpp::RE exp_port_re = app_pcre_re("/^\\s*[0-9]+\\s+([0-9]+)\\s+(?:Slot#|SLOT\\s+)([0-9]+)\\s+([^\\s]+)/mi"); // matches enclosure, port, model. - bool has_enclosure = (format_type == FormatType::Enc); + const bool has_enclosure = (format_type == FormatType::Enc); if (has_enclosure) { debug_out_dump("app", "Areca controller seems to have enclosures.\n"); } else { @@ -447,18 +447,18 @@ inline std::string areca_cli_get_drives(const std::string& cli_binary, const std std::string enclosure_str; if (exp_port_re.PartialMatch(hz::string_trim_copy(line), &enclosure_str, &port_str, &model_str)) { if (model_str != "N.A.") { - int port = hz::string_to_number_nolocale(port_str); - int enclosure = hz::string_to_number_nolocale(enclosure_str); + const int port = hz::string_to_number_nolocale(port_str); + const int enclosure = hz::string_to_number_nolocale(enclosure_str); drives.emplace_back(std::make_shared(dev, "areca," + hz::number_to_string_nolocale(port) + "/" + hz::number_to_string_nolocale(enclosure))); debug_out_info("app", "Added Areca drive " << drives.back()->get_device_with_type() << ".\n"); } } } else { // no enclosures - pcrecpp::RE port_re = (format_type == FormatType::NoEnc1 ? noexp1_port_re : noexp2_port_re); + const pcrecpp::RE port_re = (format_type == FormatType::NoEnc1 ? noexp1_port_re : noexp2_port_re); if (port_re.PartialMatch(hz::string_trim_copy(line), &port_str, &model_str)) { if (model_str != "N.A.") { - int port = hz::string_to_number_nolocale(port_str); + const int port = hz::string_to_number_nolocale(port_str); drives.emplace_back(std::make_shared(dev, "areca," + hz::number_to_string_nolocale(port))); debug_out_info("app", "Added Areca drive " << drives.back()->get_device_with_type() << ".\n"); } @@ -508,7 +508,7 @@ inline std::string detect_drives_win32_areca(std::vector& driv { debug_out_info("app", DBG_FUNC_MSG << "Detecting drives behind Areca controller(s)...\n"); - int scan_controllers = rconfig::get_data("system/win32_areca_scan_controllers"); + const int scan_controllers = rconfig::get_data("system/win32_areca_scan_controllers"); if (scan_controllers == 0) { // disabled debug_out_info("app", "Areca controller scanning is disabled through config.\n"); return {}; @@ -551,7 +551,7 @@ inline std::string detect_drives_win32_areca(std::vector& driv debug_out_dump("app", "Areca CLI installation found at: \"" << cli_inst_path << "\".\n"); } - bool cli_found = !cli_inst_path.empty(); + const bool cli_found = !cli_inst_path.empty(); int use_cli = rconfig::get_data("system/win32_areca_use_cli"); bool scan_detect = (use_cli != 1); // Whether to detect using sequential port scanning. Only do that if CLI is not forced. @@ -582,8 +582,8 @@ inline std::string detect_drives_win32_areca(std::vector& driv debug_out_dump("app", "Testing Areca controller presence using smartctl...\n"); auto drive = std::make_shared("/dev/arcmsr0", "areca,1"); - std::string error_message = drive->fetch_basic_data_and_parse(smartctl_ex); - std::string output = drive->get_info_output(); + const std::string error_message = drive->fetch_basic_data_and_parse(smartctl_ex); + const std::string output = drive->get_info_output(); if (app_pcre_match("/No Areca controller found/mi", output) || app_pcre_match("/Smartctl open device: .* failed: No such device/mi", output) ) { use_cli = 0; @@ -594,9 +594,9 @@ inline std::string detect_drives_win32_areca(std::vector& driv if (use_cli != 0) { debug_out_info("app", "Scanning Areca drives using CLI...\n"); - int cli_max_controllers = 1; // TODO controller # with CLI. + const int cli_max_controllers = 1; // TODO controller # with CLI. for (int controller_no = 0; controller_no < cli_max_controllers; ++controller_no) { - std::string error_message = areca_cli_get_drives(cli_binary.string(), + const std::string error_message = areca_cli_get_drives(cli_binary.string(), "/dev/arcmsr" + hz::number_to_string_nolocale(controller_no), controller_no, drives, ex_factory); // If we get an error on controller 0, fall back to no-cli detection. if (!error_message.empty() && controller_no == 0) { @@ -613,7 +613,7 @@ inline std::string detect_drives_win32_areca(std::vector& driv if (use_cli == 0 && scan_detect) { debug_out_info("app", "Manually scanning Areca controllers and ports...\n"); - int max_controllers = rconfig::get_data("system/win32_areca_max_controllers"); + const int max_controllers = rconfig::get_data("system/win32_areca_max_controllers"); int max_noenc_ports = rconfig::get_data("system/win32_areca_neonc_max_scan_port"); max_noenc_ports = std::max(1, std::min(24, max_noenc_ports)); // 1-24 sanity check int max_enc_ports = rconfig::get_data("system/win32_areca_enc_max_scan_port"); @@ -622,13 +622,13 @@ inline std::string detect_drives_win32_areca(std::vector& driv max_enclosures = std::max(1, std::min(8, max_enclosures)); // 1-8 sanity check for (int controller_no = 0; controller_no < max_controllers; ++controller_no) { - std::string dev = std::string("/dev/arcmsr") + hz::number_to_string_nolocale(controller_no); + const std::string dev = std::string("/dev/arcmsr") + hz::number_to_string_nolocale(controller_no); // First, scan using the areca,N format. debug_out_dump("app", "Starting brute-force port scan (no-enclosure) on 1-" << max_noenc_ports << " ports, device \"" << dev << "\". Change the maximum by setting \"system/win32_areca_neonc_max_scan_port\" config key.\n"); - std::size_t old_drive_count = drives.size(); + const std::size_t old_drive_count = drives.size(); std::string last_output; std::string error_message = smartctl_scan_drives_sequentially(dev, "areca,%d", 1, max_noenc_ports, drives, ex_factory, last_output); // If the scan stopped because of no controller, stop it all. @@ -676,7 +676,7 @@ std::string detect_drives_win32(std::vector& drives, const Com // Construct drive letter map debug_out_info("app", "Checking which drive corresponds to which \\\\.\\PhysicalDriveN device...\n"); - std::map drive_letter_map = win32_get_drive_letter_map(); + const std::map drive_letter_map = win32_get_drive_letter_map(); std::shared_ptr smartctl_ex = ex_factory->create_executor(CommandExecutorFactory::ExecutorType::Smartctl); @@ -690,26 +690,26 @@ std::string detect_drives_win32(std::vector& drives, const Com error_msgs.push_back(error_message); } - bool multiport_found = !drives.empty(); + const bool multiport_found = !drives.empty(); bool areca_open_found = false; // whether areca devices were found at --scan-open time. // Find out their serial numbers and whether there are Arecas there. std::map serials; for (auto& drive : drives) { - std::string local_error = drive->fetch_basic_data_and_parse(smartctl_ex); + const std::string local_error = drive->fetch_basic_data_and_parse(smartctl_ex); if (!local_error.empty()) { debug_out_info("app", "Smartctl returned with an error: " << local_error << "\n"); // Don't exit, just report it. } if (!drive->get_serial_number().empty()) { // add model as well, who knows, there may be duplicates across vendors - std::string drive_serial_id = drive->get_model_name() + "_" + drive->get_serial_number(); + const std::string drive_serial_id = drive->get_model_name() + "_" + drive->get_serial_number(); serials[drive_serial_id] = drive; } // See if there are any areca devices. This is not implemented yet by smartctl (as of 6.0), // but if it ever is, we can skip our own detection below. - std::string type_arg = drive->get_type_argument(); + const std::string type_arg = drive->get_type_argument(); if (type_arg.find("areca") != std::string::npos) { areca_open_found = true; } @@ -730,7 +730,7 @@ std::string detect_drives_win32(std::vector& drives, const Com continue; } - std::string phys_name = hz::string_sprintf("\\\\.\\PhysicalDrive%d", drive_num); + const std::string phys_name = hz::string_sprintf("\\\\.\\PhysicalDrive%d", drive_num); #ifdef _WIN32 // If the drive is openable, then it's there. Yes, CreateFile() is open, not create. @@ -771,13 +771,13 @@ std::string detect_drives_win32(std::vector& drives, const Com // they contain more information. // The only way to detect these duplicates is to compare them using serial numbers. if (!serials.empty()) { - std::string local_error = drive->fetch_basic_data_and_parse(smartctl_ex); + const std::string local_error = drive->fetch_basic_data_and_parse(smartctl_ex); if (!local_error.empty()) { debug_out_info("app", "Smartctl returned with an error: " << local_error << "\n"); // Don't exit, just report it. } - std::string drive_serial_id = drive->get_model_name() + "_" + drive->get_serial_number(); + const std::string drive_serial_id = drive->get_model_name() + "_" + drive->get_serial_number(); // A serial may be empty if "-q noserial" was given to smartctl. if (!drive->get_serial_number().empty() && serials.count(drive_serial_id) > 0) { debug_out_info("app", "Skipping drive due to duplicate S/N: model: \"" << drive->get_model_name() @@ -809,7 +809,7 @@ std::string detect_drives_win32(std::vector& drives, const Com std::vector controllers; error_message = tw_cli_get_controllers(ex_factory, controllers); // ignore the error message above, it's of no use. - for (int controller : controllers) { + for (const int controller : controllers) { // don't specify device, it's ignored in tw_cli mode tw_cli_get_drives("", controller, drives, ex_factory, true); } diff --git a/src/applib/storage_device.cpp b/src/applib/storage_device.cpp index 33d0122..6626597 100644 --- a/src/applib/storage_device.cpp +++ b/src/applib/storage_device.cpp @@ -219,7 +219,7 @@ std::string StorageDevice::parse_basic_data(bool do_set_properties, bool emit_si std::string rpm_str; if (app_pcre_match("/^Rotation Rate:[ \\t]*(.*)$/mi", info_output_, &rpm_str)) { - int rpm = hz::string_to_number_nolocale(rpm_str, false); + const int rpm = hz::string_to_number_nolocale(rpm_str, false); hdd_ = rpm > 0; } @@ -543,7 +543,7 @@ std::string StorageDevice::get_device_base() const if (is_virtual_) return ""; - std::string::size_type pos = device_.rfind('/'); // find basename + const std::string::size_type pos = device_.rfind('/'); // find basename if (pos == std::string::npos) return device_; // fall back return device_.substr(pos+1, std::string::npos); @@ -554,7 +554,7 @@ std::string StorageDevice::get_device_base() const std::string StorageDevice::get_device_with_type() const { if (this->get_is_virtual()) { - std::string vf = this->get_virtual_filename(); + const std::string vf = this->get_virtual_filename(); /// Translators: %1 is filename std::string ret = Glib::ustring::compose(C_("filename", "Virtual (%1)"), (vf.empty() ? (std::string("[") + C_("filename", "empty") + "]") : vf)); return ret; @@ -773,9 +773,9 @@ bool StorageDevice::get_test_is_active() const std::string StorageDevice::get_save_filename() const { - std::string model = this->get_model_name(); // may be empty - std::string serial = this->get_serial_number(); - std::string date = hz::format_date("%Y-%m-%d_%H%M", true); + const std::string model = this->get_model_name(); // may be empty + const std::string serial = this->get_serial_number(); + const std::string date = hz::format_date("%Y-%m-%d_%H%M", true); auto filename_format = rconfig::get_data("gui/smartctl_output_filename_format"); hz::string_replace(filename_format, "{serial}", serial); diff --git a/src/gsc_add_device_window.cpp b/src/gsc_add_device_window.cpp index 16c0ad0..b7bd01d 100644 --- a/src/gsc_add_device_window.cpp +++ b/src/gsc_add_device_window.cpp @@ -40,7 +40,7 @@ GscAddDeviceWindow::GscAddDeviceWindow(BaseObjectType* gtkcobj, Glib::RefPtr("top_info_link_label"); - std::string man_url = "https://gsmartcontrol.shaduri.dev/smartctl_man.html"; + const std::string man_url = "https://gsmartcontrol.shaduri.dev/smartctl_man.html"; top_info_link_label->set_text(Glib::ustring::compose(top_info_link_label->get_text(), man_url)); Glib::ustring device_name_tooltip = _("Device name"); @@ -166,8 +166,6 @@ void GscAddDeviceWindow::on_window_ok_button_clicked() void GscAddDeviceWindow::on_device_name_browse_button_clicked() { - std::string default_file; - auto* entry = this->lookup_widget("device_name_entry"); if (!entry) return; diff --git a/src/gsc_info_window.cpp b/src/gsc_info_window.cpp index b232344..86a3019 100644 --- a/src/gsc_info_window.cpp +++ b/src/gsc_info_window.cpp @@ -81,7 +81,7 @@ namespace { // add one label per element for (const auto& label_string : label_strings) { - std::string label_text = (label_string.markup ? Glib::ustring(label_string.label) : Glib::Markup::escape_text( + const std::string label_text = (label_string.markup ? Glib::ustring(label_string.label) : Glib::Markup::escape_text( label_string.label)); Gtk::Label* label = Gtk::manage(new Gtk::Label()); label->set_markup(label_text); @@ -140,9 +140,9 @@ namespace { auto* textview = window->lookup_widget("error_log_textview"); Glib::RefPtr buffer; if (treeview != nullptr && textview != nullptr && (buffer = textview->get_buffer())) { - Gtk::TreeModel::iterator iter = treeview->get_selection()->get_selected(); + auto iter = treeview->get_selection()->get_selected(); if (iter) { - Glib::RefPtr mark = buffer->get_mark((*iter)[mark_name_column]); + auto mark = buffer->get_mark((*iter)[mark_name_column]); if (mark) textview->scroll_to(mark, 0., 0., 0.); } @@ -161,8 +161,8 @@ GscInfoWindow::GscInfoWindow(BaseObjectType* gtkcobj, Glib::RefPtr { // Size { - int def_size_w = rconfig::get_data("gui/info_window/default_size_w"); - int def_size_h = rconfig::get_data("gui/info_window/default_size_h"); + const int def_size_w = rconfig::get_data("gui/info_window/default_size_w"); + const int def_size_h = rconfig::get_data("gui/info_window/default_size_h"); if (def_size_w > 0 && def_size_h > 0) { set_default_size(def_size_w, def_size_h); } @@ -348,7 +348,7 @@ void GscInfoWindow::fill_ui_with_info(bool scan, bool clear_ui, bool clear_tests if (scan) { std::shared_ptr ex(new SmartctlExecutorGui()); ex->create_running_dialog(this, Glib::ustring::compose(_("Running {command} on %1..."), drive->get_device_with_type())); - std::string error_msg = drive->fetch_data_and_parse(ex); // run it with GUI support + const std::string error_msg = drive->fetch_data_and_parse(ex); // run it with GUI support if (!error_msg.empty()) { gsc_executor_error_dialog_show(_("Cannot retrieve SMART data"), error_msg, this); @@ -370,25 +370,25 @@ void GscInfoWindow::fill_ui_with_info(bool scan, bool clear_ui, bool clear_tests // hide all tabs except the first if smart is disabled, because they may contain // completely random data (smartctl does that sometimes). if (get_startup_settings().hide_tabs_on_smart_disabled) { - bool smart_enabled = (drive->get_smart_status() == StorageDevice::Status::enabled); + const bool smart_enabled = (drive->get_smart_status() == StorageDevice::Status::enabled); Gtk::Widget* note_page_box = nullptr; - if ((note_page_box = lookup_widget("attributes_tab_vbox")) != nullptr) { + if (note_page_box = lookup_widget("attributes_tab_vbox"); note_page_box != nullptr) { if (smart_enabled) { note_page_box->show(); } else { note_page_box->hide(); } } - if ((note_page_box = lookup_widget("statistics_tab_vbox")) != nullptr) { + if (note_page_box = lookup_widget("statistics_tab_vbox"); note_page_box != nullptr) { if (smart_enabled) { note_page_box->show(); } else { note_page_box->hide(); } } - if ((note_page_box = lookup_widget("test_tab_vbox")) != nullptr) { + if (note_page_box = lookup_widget("test_tab_vbox"); note_page_box != nullptr) { if (smart_enabled) { note_page_box->show(); } else { note_page_box->hide(); } } - if ((note_page_box = lookup_widget("error_log_tab_vbox")) != nullptr) { + if (note_page_box = lookup_widget("error_log_tab_vbox"); note_page_box != nullptr) { if (smart_enabled) { note_page_box->show(); } else { note_page_box->hide(); } } - if ((note_page_box = lookup_widget("temperature_log_tab_vbox")) != nullptr) { + if (note_page_box = lookup_widget("temperature_log_tab_vbox"); note_page_box != nullptr) { if (smart_enabled) { note_page_box->show(); } else { note_page_box->hide(); } } - if ((note_page_box = lookup_widget("advanced_tab_vbox")) != nullptr) { + if (note_page_box = lookup_widget("advanced_tab_vbox"); note_page_box != nullptr) { if (smart_enabled) { note_page_box->show(); } else { note_page_box->hide(); } } if (auto* notebook = lookup_widget("main_notebook")) { @@ -398,9 +398,9 @@ void GscInfoWindow::fill_ui_with_info(bool scan, bool clear_ui, bool clear_tests // Top label - short device information { - std::string device = Glib::Markup::escape_text(drive->get_device_with_type()); - std::string model = Glib::Markup::escape_text(drive->get_model_name().empty() ? _("Unknown model") : drive->get_model_name()); - std::string drive_letters = Glib::Markup::escape_text(drive->format_drive_letters(false)); + const std::string device = Glib::Markup::escape_text(drive->get_device_with_type()); + const std::string model = Glib::Markup::escape_text(drive->get_model_name().empty() ? _("Unknown model") : drive->get_model_name()); + const std::string drive_letters = Glib::Markup::escape_text(drive->format_drive_letters(false)); /// Translators: %1 is device name, %2 is device model. this->set_title(Glib::ustring::compose(_("Device Information - %1: %2 - GSmartControl"), device, model)); @@ -430,13 +430,13 @@ void GscInfoWindow::fill_ui_with_info(bool scan, bool clear_ui, bool clear_tests fill_ui_temperature_log(props); // Advanced tab - WarningLevel caps_warning_level = fill_ui_capabilities(props); - WarningLevel errc_warning_level = fill_ui_error_recovery(props); - WarningLevel selective_warning_level = fill_ui_selective_self_test_log(props); - WarningLevel dir_warning_level = fill_ui_directory(props); - WarningLevel phy_warning_level = fill_ui_physical(props); + auto caps_warning_level = fill_ui_capabilities(props); + auto errc_warning_level = fill_ui_error_recovery(props); + auto selective_warning_level = fill_ui_selective_self_test_log(props); + auto dir_warning_level = fill_ui_directory(props); + auto phy_warning_level = fill_ui_physical(props); - WarningLevel max_advanced_tab_warning = std::max({ + auto max_advanced_tab_warning = std::max({ caps_warning_level, errc_warning_level, selective_warning_level, @@ -467,7 +467,7 @@ void GscInfoWindow::clear_ui_info(bool clear_tests_too) auto* identity_table = lookup_widget("identity_table"); if (identity_table) { // manually remove all children. without this visual corruption occurs. - std::vector children = identity_table->get_children(); + auto children = identity_table->get_children(); for (auto& widget : children) { identity_table->remove(*widget); } @@ -696,7 +696,7 @@ void GscInfoWindow::on_view_output_button_clicked() win->set_text_from_command(_("Smartctl Output"), output); - std::string filename = drive->get_save_filename(); + const std::string filename = drive->get_save_filename(); if (!filename.empty()) win->set_save_filename(filename); @@ -713,7 +713,7 @@ void GscInfoWindow::on_save_info_button_clicked() } int result = 0; - std::string filename = drive->get_save_filename(); + const std::string filename = drive->get_save_filename(); Glib::RefPtr specific_filter = Gtk::FileFilter::create(); specific_filter->set_name(_("Text Files")); @@ -786,7 +786,7 @@ void GscInfoWindow::on_save_info_button_clicked() if (data.empty()) { data = this->drive->get_info_output(); } - std::error_code ec = hz::fs_file_put_contents(file, data); + const std::error_code ec = hz::fs_file_put_contents(file, data); if (ec) { gui_show_error_dialog(_("Cannot save SMART data to file"), ec.message(), this); } @@ -1926,8 +1926,8 @@ gboolean GscInfoWindow::test_idle_callback(void* data) break; } - int8_t rem_percent = self->current_test->get_remaining_percent(); - std::string rem_percent_str = (rem_percent == -1 ? C_("value", "Unknown") : hz::number_to_string_locale(100 - rem_percent)); + const int8_t rem_percent = self->current_test->get_remaining_percent(); + const std::string rem_percent_str = (rem_percent == -1 ? C_("value", "Unknown") : hz::number_to_string_locale(100 - rem_percent)); auto poll_in = self->current_test->get_poll_in_seconds(); // sec @@ -1944,7 +1944,7 @@ gboolean GscInfoWindow::test_idle_callback(void* data) auto rem_seconds = self->current_test->get_remaining_seconds(); if (test_completion_progressbar) { - std::string rem_seconds_str = (rem_seconds == std::chrono::seconds(-1) ? C_("duration", "Unknown") : hz::format_time_length(rem_seconds)); + const std::string rem_seconds_str = (rem_seconds == std::chrono::seconds(-1) ? C_("duration", "Unknown") : hz::format_time_length(rem_seconds)); Glib::ustring bar_str; @@ -2004,7 +2004,7 @@ gboolean GscInfoWindow::test_idle_callback(void* data) self->test_timer_poll.stop(); // just in case self->test_timer_bar.stop(); // just in case - AtaStorageSelftestEntry::Status status = self->current_test->get_status(); + auto status = self->current_test->get_status(); bool aborted = false; AtaStorageSelftestEntry::StatusSeverity severity = AtaStorageSelftestEntry::StatusSeverity::none; @@ -2097,7 +2097,7 @@ void GscInfoWindow::on_test_execute_button_clicked() std::shared_ptr ex(new SmartctlExecutorGui()); ex->create_running_dialog(this); - std::string error_msg = test->start(ex); // this runs update() too. + const std::string error_msg = test->start(ex); // this runs update() too. if (!error_msg.empty()) { /// Translators: %1 is test name gui_show_error_dialog(Glib::ustring::compose(_("Cannot run %1"), SelfTest::get_test_displayable_name(test->get_test_type())), error_msg, this); @@ -2159,7 +2159,7 @@ void GscInfoWindow::on_test_stop_button_clicked() std::shared_ptr ex(new SmartctlExecutorGui()); ex->create_running_dialog(this); - std::string error_msg = current_test->force_stop(ex); + const std::string error_msg = current_test->force_stop(ex); if (!error_msg.empty()) { /// Translators: %1 is test name gui_show_error_dialog(Glib::ustring::compose(_("Cannot stop %1"), SelfTest::get_test_displayable_name(current_test->get_test_type())), error_msg, this); @@ -2180,7 +2180,7 @@ void GscInfoWindow::on_drive_changed([[maybe_unused]] StorageDevice* pdrive) { if (!drive) return; - bool test_active = drive->get_test_is_active(); + const bool test_active = drive->get_test_is_active(); // disable refresh button if test is active or if it's a virtual drive if (auto* refresh_info_button = lookup_widget("refresh_info_button")) @@ -2201,7 +2201,7 @@ void GscInfoWindow::on_drive_changed([[maybe_unused]] StorageDevice* pdrive) bool GscInfoWindow::on_treeview_button_press_event(GdkEventButton* button_event, Gtk::Menu* menu, Gtk::TreeView* treeview) { if (button_event->type == GDK_BUTTON_PRESS && button_event->button == 3) { - bool selection_empty = treeview->get_selection()->get_selected_rows().empty(); + const bool selection_empty = treeview->get_selection()->get_selected_rows().empty(); std::vector children = menu->get_children(); for (auto& child : children) { child->set_sensitive(!selection_empty); @@ -2233,7 +2233,7 @@ void GscInfoWindow::on_treeview_menu_copy_clicked(Gtk::TreeView* treeview) Gtk::TreeRow row = *(list_store->get_iter(path)); for (int j = 0; j < num_cols; ++j) { // gather data only from tree columns, not model columns (like tooltips and helper data) - GType type = list_store->get_column_type(j); + const GType type = list_store->get_column_type(j); if (type == G_TYPE_INT) { int32_t value = 0; row.get_value(j, value); diff --git a/src/gsc_init.cpp b/src/gsc_init.cpp index 465a24e..1d9521e 100644 --- a/src/gsc_init.cpp +++ b/src/gsc_init.cpp @@ -16,12 +16,14 @@ Copyright: #include // #include // _configthreadlocale (win32) #include // std::runtime_error -#include // std::printf #include #include #include #include #include +#include + + #ifdef _WIN32 #include @@ -119,7 +121,7 @@ namespace { } else { // create the parent directories of the config file - hz::fs::path config_loc = get_home_config_file().parent_path(); + const hz::fs::path config_loc = get_home_config_file().parent_path(); if (!hz::fs::exists(config_loc, ec)) { hz::fs::create_directories(config_loc, ec); hz::fs::permissions(config_loc, hz::fs::perms::owner_all, ec); @@ -131,7 +133,7 @@ namespace { rconfig::dump_config(); rconfig::autosave_set_config_file(get_home_config_file()); - int autosave_timeout_sec = rconfig::get_data("system/config_autosave_timeout_sec"); + const int autosave_timeout_sec = rconfig::get_data("system/config_autosave_timeout_sec"); if (autosave_timeout_sec > 0) { rconfig::autosave_start(std::chrono::seconds(autosave_timeout_sec)); } @@ -253,7 +255,7 @@ namespace { // The command-line parser stops at the first unknown option. Since this // is kind of inconsistent, we abort altogether. - bool parsed = static_cast(g_option_context_parse(context, &argc, &argv, &error)); + const bool parsed = static_cast(g_option_context_parse(context, &argc, &argv, &error)); if (error) { std::string error_text = "\n" + Glib::ustring::compose(_("Error parsing command-line options: %1"), (error->message ? error->message : "invalid error")); @@ -266,7 +268,7 @@ namespace { g_free(help_text); } - std::fprintf(stderr, "%s", error_text.c_str()); + std::cerr << error_text; } g_option_context_free(context); @@ -278,7 +280,7 @@ namespace { /// Print application version information inline void app_print_version_info() { - std::string versiontext = "\n" + Glib::ustring::compose(_("GSmartControl version %1"), BuildEnv::package_version()) + "\n"; + const std::string versiontext = "\n" + Glib::ustring::compose(_("GSmartControl version %1"), BuildEnv::package_version()) + "\n"; std::string warningtext = std::string("\n") + _("Warning: GSmartControl comes with ABSOLUTELY NO WARRANTY.\n" "See LICENSE.txt file for details.") + "\n\n"; @@ -286,7 +288,7 @@ namespace { warningtext += Glib::ustring::compose(_("Copyright (C) %1 Alexander Shaduri %2"), "2008 - 2021", "") + "\n\n"; - std::fprintf(stdout, "%s%s", versiontext.c_str(), warningtext.c_str()); + std::cout << versiontext << warningtext; } } @@ -360,7 +362,7 @@ bool app_init_and_loop(int& argc, char**& argv) load_virtuals.emplace_back(entry); } } - std::string load_virtuals_str = hz::string_join(load_virtuals, ", "); // for display purposes only + const std::string load_virtuals_str = hz::string_join(load_virtuals, ", "); // for display purposes only std::vector load_devices; if (args.arg_add_device) { @@ -369,7 +371,7 @@ bool app_init_and_loop(int& argc, char**& argv) load_devices.emplace_back(entry); } } - std::string load_devices_str = hz::string_join(load_devices, "; "); // for display purposes only + const std::string load_devices_str = hz::string_join(load_devices, "; "); // for display purposes only // it's here because earlier there are no domains @@ -415,7 +417,7 @@ bool app_init_and_loop(int& argc, char**& argv) // Save the locale - std::locale final_loc_cpp = hz::locale_cpp_get(); + const std::locale final_loc_cpp = hz::locale_cpp_get(); // Initialize GTK+ (it's already initialized by command-line parser, // so this doesn't do much). @@ -452,7 +454,7 @@ bool app_init_and_loop(int& argc, char**& argv) auto application_dir = hz::fs_get_application_dir(); debug_out_info("app", "Application directory: " << application_dir << "\n"); - bool is_from_source = !application_dir.empty() && hz::fs::exists((application_dir / "src")); // this covers standard cmake builds, but not VS. + const bool is_from_source = !application_dir.empty() && hz::fs::exists((application_dir / "src")); // this covers standard cmake builds, but not VS. // Add data file search paths if (is_from_source) { @@ -488,7 +490,7 @@ bool app_init_and_loop(int& argc, char**& argv) { Glib::RefPtr gtk_settings = Gtk::Settings::get_default(); if (gtk_settings) { - Glib::ustring theme_name = gtk_settings->property_gtk_theme_name().get_value(); + const Glib::ustring theme_name = gtk_settings->property_gtk_theme_name().get_value(); debug_out_dump("app", "Current GTK theme: " << theme_name << "\n"); bool windows_is_using_classic_theme = false; #ifdef _WIN32 diff --git a/src/gsc_main_window_iconview.h b/src/gsc_main_window_iconview.h index 50d256e..90887f0 100644 --- a/src/gsc_main_window_iconview.h +++ b/src/gsc_main_window_iconview.h @@ -183,8 +183,8 @@ class GscMainWindowIconView : public Gtk::IconView { int layout_w = 0, layout_h = 0; layout->get_pixel_size(layout_w, layout_h); - int pos_x = (get_allocation().get_width() - layout_w) / 2; - int pos_y = (get_allocation().get_height() - layout_h) / 2; + const int pos_x = (get_allocation().get_width() - layout_w) / 2; + const int pos_y = (get_allocation().get_height() - layout_h) / 2; cr->move_to(pos_x, pos_y); layout->show_in_cairo_context(cr); @@ -243,7 +243,7 @@ class GscMainWindowIconView : public Gtk::IconView { drive->signal_changed().connect(sigc::mem_fun(this, &GscMainWindowIconView::on_drive_changed)); if (scroll_to_it) { - Gtk::TreeModel::Path tpath(row); + const Gtk::TreeModel::Path tpath(row); // scroll_to_path() and set/get_cursor() are since gtkmm 2.8. this->scroll_to_path(tpath, true, 0.5, 0.5); @@ -297,7 +297,7 @@ class GscMainWindowIconView : public Gtk::IconView { name += (drive->get_model_name().empty() ? Glib::ustring("Unknown model") : Glib::Markup::escape_text(drive->get_model_name())); if (rconfig::get_data("gui/icons_show_device_name")) { if (!drive->get_is_virtual()) { - std::string dev = Glib::Markup::escape_text(drive->get_device_with_type()); + const std::string dev = Glib::Markup::escape_text(drive->get_device_with_type()); if constexpr(BuildEnv::is_kernel_family_windows()) { name += "\n" + Glib::ustring::compose(_("%1 (%2)"), dev, drive_letters); } else { @@ -321,7 +321,7 @@ class GscMainWindowIconView : public Gtk::IconView { std::vector tooltip_strs; if (drive->get_is_virtual()) { - std::string vfile = drive->get_virtual_filename(); + const std::string vfile = drive->get_virtual_filename(); tooltip_strs.push_back(Glib::ustring::compose(_("Loaded from: %1"), (vfile.empty() ? (Glib::ustring("[") + C_("name", "empty") + "]") : Glib::Markup::escape_text(vfile)))); if (!scan_time_prop.empty() && !scan_time_prop.get_value().empty()) { tooltip_strs.push_back(Glib::ustring::compose(_("Scanned on: "), Glib::Markup::escape_text(scan_time_prop.get_value()))); @@ -357,15 +357,15 @@ class GscMainWindowIconView : public Gtk::IconView { break; } - AtaStorageProperty health_prop = drive->get_health_property(); + const AtaStorageProperty health_prop = drive->get_health_property(); if (health_prop.warning_level != WarningLevel::none && health_prop.generic_name == "smart_status/passed") { if (icon) { icon = icon->copy(); // work on a copy if (icon->get_colorspace() == Gdk::COLORSPACE_RGB && icon->get_bits_per_sample() == 8) { - std::ptrdiff_t n_channels = icon->get_n_channels(); - std::ptrdiff_t icon_width = icon->get_width(); - std::ptrdiff_t icon_height = icon->get_height(); - std::ptrdiff_t rowstride = icon->get_rowstride(); + const std::ptrdiff_t n_channels = icon->get_n_channels(); + const std::ptrdiff_t icon_width = icon->get_width(); + const std::ptrdiff_t icon_height = icon->get_height(); + const std::ptrdiff_t rowstride = icon->get_rowstride(); guint8* pixels = icon->get_pixels(); for (std::ptrdiff_t y = 0; y < icon_height; ++y) { @@ -403,7 +403,7 @@ class GscMainWindowIconView : public Gtk::IconView { /// Remove drive entry void remove_entry(const Gtk::TreePath& model_path) { - Gtk::TreeModel::Row row = *(ref_list_model->get_iter(model_path)); + const Gtk::TreeModel::Row row = *(ref_list_model->get_iter(model_path)); ref_list_model->erase(row); } @@ -414,7 +414,7 @@ class GscMainWindowIconView : public Gtk::IconView { { const auto& selected_items = this->get_selected_items(); if (!selected_items.empty()) { - Gtk::TreePath model_path = *(selected_items.begin()); + const Gtk::TreePath model_path = *(selected_items.begin()); this->remove_entry(model_path); } } @@ -429,7 +429,7 @@ class GscMainWindowIconView : public Gtk::IconView { // this is needed to update the label from "disabled" to "scanning" if (this->get_realized()) { - Gdk::Rectangle rect = this->get_allocation(); + const Gdk::Rectangle rect = this->get_allocation(); Glib::RefPtr win = this->get_window(); win->invalidate_rect(rect, true); // force expose event win->process_updates(false); // update immediately @@ -444,8 +444,8 @@ class GscMainWindowIconView : public Gtk::IconView { StorageDevicePtr drive; const auto& selected_items = this->get_selected_items(); if (!selected_items.empty()) { - Gtk::TreePath model_path = *(selected_items.begin()); - Gtk::TreeModel::Row row = *(ref_list_model->get_iter(model_path)); + const Gtk::TreePath model_path = *(selected_items.begin()); + const Gtk::TreeModel::Row row = *(ref_list_model->get_iter(model_path)); drive = row[col_drive_ptr]; } return drive; @@ -456,7 +456,7 @@ class GscMainWindowIconView : public Gtk::IconView { /// Get tree path by a drive Gtk::TreePath get_path_by_drive(StorageDevice* drive) { - Gtk::TreeNodeChildren children = ref_list_model->children(); + const Gtk::TreeNodeChildren children = ref_list_model->children(); for (const auto& row : children) { // convert iter to row (iter is row's base, but can we cast it?) if (drive == row.get_value(col_drive_ptr).get()) @@ -475,8 +475,8 @@ class GscMainWindowIconView : public Gtk::IconView { main_window->set_drive_menu_status(nullptr); } else { // enable drives menu, set proper smart toggles - Gtk::TreePath model_path = *(this->get_selected_items().begin()); - Gtk::TreeModel::Row row = *(ref_list_model->get_iter(model_path)); + const Gtk::TreePath model_path = *(this->get_selected_items().begin()); + const Gtk::TreeModel::Row row = *(ref_list_model->get_iter(model_path)); if (!row[col_populated]) { // protect against using incomplete model entry return; } @@ -494,7 +494,7 @@ class GscMainWindowIconView : public Gtk::IconView { if (!main_window) return; - Gtk::TreeModel::Row row = *(ref_list_model->get_iter(model_path)); + const Gtk::TreeModel::Row row = *(ref_list_model->get_iter(model_path)); if (!row[col_populated]) { // protect against using incomplete model entry return; } @@ -539,7 +539,7 @@ class GscMainWindowIconView : public Gtk::IconView { // select the icon this->select_path(tpath); - Gtk::TreeModel::Row row = *(ref_list_model->get_iter(tpath)); + const Gtk::TreeModel::Row row = *(ref_list_model->get_iter(tpath)); drive = row[col_drive_ptr]; } else { @@ -562,7 +562,7 @@ class GscMainWindowIconView : public Gtk::IconView { /// Callback attached to StorageDevice, updates its view. void on_drive_changed(StorageDevice* drive) { - Gtk::TreePath model_path = this->get_path_by_drive(drive); + const Gtk::TreePath model_path = this->get_path_by_drive(drive); this->decorate_entry(model_path); this->update_menu_actions(); main_window->update_status_widgets(); diff --git a/src/rconfig/autosave.h b/src/rconfig/autosave.h index da70674..101ac1c 100644 --- a/src/rconfig/autosave.h +++ b/src/rconfig/autosave.h @@ -72,7 +72,7 @@ extern "C" { return static_cast(force); // if manual, return failure. else, don't stop the timeout. } - bool status = rconfig::save_to_file(impl::autosave_config_file); + const bool status = rconfig::save_to_file(impl::autosave_config_file); if (force) return static_cast(status); // return status to caller diff --git a/src/rconfig/loadsave.h b/src/rconfig/loadsave.h index 598e1c7..ba32f2e 100644 --- a/src/rconfig/loadsave.h +++ b/src/rconfig/loadsave.h @@ -52,7 +52,7 @@ inline bool load_from_file(const hz::fs::path& file) /// Save the config branch to a file. inline bool save_to_file(const hz::fs::path& file) { - std::string json_str = get_config_branch().dump(4); + const std::string json_str = get_config_branch().dump(4); auto ec = hz::fs_file_put_contents(file, json_str); if (ec) {