diff --git a/src/applib/command_executor_areca.h b/src/applib/command_executor_areca.h index a481625..cc53dd8 100644 --- a/src/applib/command_executor_areca.h +++ b/src/applib/command_executor_areca.h @@ -76,7 +76,7 @@ ArecaCliExecutorGeneric::ArecaCliExecutorGeneric() template std::string ArecaCliExecutorGeneric::translate_exit_status([[maybe_unused]] int status) { - return std::string(); + return {}; } diff --git a/src/applib/examples/example_smartctl_executor.cpp b/src/applib/examples/example_smartctl_executor.cpp index 6314d4d..db8292b 100644 --- a/src/applib/examples/example_smartctl_executor.cpp +++ b/src/applib/examples/example_smartctl_executor.cpp @@ -38,7 +38,7 @@ int main(int argc, char** argv) ex.execute(); - std::string out_str = ex.get_stdout_str(); + const std::string out_str = ex.get_stdout_str(); // std::cout << "OUT:\n" << out_str << "\n\n"; std::cerr << "OUT SIZE: " << out_str.size() << "\n"; diff --git a/src/applib/smartctl_ata_json_parser.cpp b/src/applib/smartctl_ata_json_parser.cpp index 81ca54d..49d14a3 100644 --- a/src/applib/smartctl_ata_json_parser.cpp +++ b/src/applib/smartctl_ata_json_parser.cpp @@ -9,6 +9,8 @@ Copyright: /// \weakgroup applib /// @{ +#include + #include "smartctl_ata_json_parser.h" #include "json/json.hpp" #include "hz/debug.h" @@ -93,7 +95,7 @@ T get_node_data(const nlohmann::json& root, const std::string& path) const std::string& comp_name = components[comp_index]; if (!curr->is_object()) { // we can't have non-object values in the middle of a path - throw std::runtime_error("Cannot get node data \""s + path + "\", component \"" + comp_name + "\" is not an object."); + throw std::runtime_error(std::format("Cannot get node data \"{}\", component \"{}\" is not an object.", path, comp_name)); } if (auto iter = curr->find(comp_name); iter != curr->end()) { // path component exists const auto& jval = iter.value(); @@ -109,7 +111,7 @@ T get_node_data(const nlohmann::json& root, const std::string& path) curr = &jval; } else { // path component doesn't exist - throw std::runtime_error("Cannot get node data \""s + path + "\", component \"" + comp_name + "\" does not exist."); + throw std::runtime_error(std::format("Cannot get node data \"{}\", component \"{}\" does not exist.", path, comp_name)); } } @@ -197,6 +199,8 @@ hz::ExpectedVoid SmartctlAtaJsonParser::parse_full(const st debug_out_warn("app", DBG_FUNC_MSG << "Error parsing smartctl output as JSON: " << e.what() << "\n"); return hz::Unexpected(SmartctlParserError::SyntaxError, std::string("Invalid JSON data: ") + e.what()); } + + return {}; } diff --git a/src/gsc_executor_error_dialog.cpp b/src/gsc_executor_error_dialog.cpp index ae2c48e..106cf05 100644 --- a/src/gsc_executor_error_dialog.cpp +++ b/src/gsc_executor_error_dialog.cpp @@ -56,7 +56,7 @@ namespace { dialog.set_default_response(Gtk::RESPONSE_OK); - int response = dialog.run(); // blocks until the dialog is closed + const int response = dialog.run(); // blocks until the dialog is closed return response; } @@ -70,7 +70,7 @@ namespace { void gsc_executor_error_dialog_show(const std::string& message, const std::string& sec_message, Gtk::Window* parent, bool sec_msg_markup, bool show_output_button) { - int response = show_executor_dialog(Gtk::MESSAGE_ERROR, message, sec_message, + const int response = show_executor_dialog(Gtk::MESSAGE_ERROR, message, sec_message, parent, sec_msg_markup, show_output_button); if (response == Gtk::RESPONSE_HELP) { @@ -87,7 +87,7 @@ void gsc_no_info_dialog_show(const std::string& message, const std::string& sec_ Gtk::Window* parent, bool sec_msg_markup, const std::string& output, const std::string& output_window_title, const std::string& default_save_filename) { - int response = show_executor_dialog(Gtk::MESSAGE_WARNING, message, sec_message, + const int response = show_executor_dialog(Gtk::MESSAGE_WARNING, message, sec_message, parent, sec_msg_markup, !output.empty()); if (response == Gtk::RESPONSE_HELP) { diff --git a/src/hz/bad_cast_exception.h b/src/hz/bad_cast_exception.h index b8328f0..b5a9f70 100644 --- a/src/hz/bad_cast_exception.h +++ b/src/hz/bad_cast_exception.h @@ -47,7 +47,7 @@ class bad_cast_except : public std::exception { // from { // Note: we do quite a lot of construction here, but since it's not // an out-of-memory exception, what the heck. - std::string who = (self_name_.empty() ? "[unknown]" : self_name_); + const std::string who = (self_name_.empty() ? "[unknown]" : self_name_); std::string from = (src_type_ == typeid(void) ? "[unknown]" : hz::type_name_demangle(src_type_.name())); if (from.empty()) diff --git a/src/hz/format_unit.h b/src/hz/format_unit.h index e57deb0..73c83c0 100644 --- a/src/hz/format_unit.h +++ b/src/hz/format_unit.h @@ -163,13 +163,13 @@ inline std::string format_time_length(std::chrono::seconds secs) if (secs >= 100h) { day_unit days = std::chrono::round(secs); - std::chrono::seconds sec_diff = secs - days; // difference between days and actual time (may be positive or negative) + const std::chrono::seconds sec_diff = secs - days; // difference between days and actual time (may be positive or negative) if (days.count() < 10) { // if less than 10 days, display hours too // if there's more than half an hour missing from complete day, add a day. // then add half an hour and convert to hours. - int64_t hours = ((sec_diff.count() < (-hour_size / 2) ? sec_diff.count() + day_size : sec_diff.count()) + hour_size / 2) / hour_size; + const int64_t hours = ((sec_diff.count() < (-hour_size / 2) ? sec_diff.count() + day_size : sec_diff.count()) + hour_size / 2) / hour_size; if (hours > 0 && sec_diff.count() < (-hour_size / 2)) days--; @@ -185,10 +185,10 @@ inline std::string format_time_length(std::chrono::seconds secs) if (secs >= 100min) { auto hours = std::chrono::round(secs); - std::chrono::seconds sec_diff = secs - hours; + const std::chrono::seconds sec_diff = secs - hours; if (hours.count() < 10) { // if less than 10 hours, display minutes too - int64_t minutes = ((sec_diff.count() < (-min_size / 2) ? sec_diff.count() + hour_size : sec_diff.count()) + min_size / 2) / min_size; + const int64_t minutes = ((sec_diff.count() < (-min_size / 2) ? sec_diff.count() + hour_size : sec_diff.count()) + min_size / 2) / min_size; if (minutes > 0 && sec_diff.count() < (-min_size / 2)) hours--; diff --git a/src/hz/fs.h b/src/hz/fs.h index cc7566c..3f6e767 100644 --- a/src/hz/fs.h +++ b/src/hz/fs.h @@ -210,7 +210,7 @@ inline std::error_code fs_file_get_contents_noalloc(const fs::path& file, unsign } // automatically allocate the buffer if buf_size is -1. - bool auto_alloc = (buf_size == static_cast(-1)); + const bool auto_alloc = (buf_size == static_cast(-1)); if (!auto_alloc && buf_size < size) { ec = std::make_error_code(std::errc::no_buffer_space); break; // goto cleanup @@ -225,7 +225,7 @@ inline std::error_code fs_file_get_contents_noalloc(const fs::path& file, unsign // We don't need large file support here because we read into memory, // which is limited at 31 bits anyway (on 32-bit systems). // I really hope this is not a byte-by-byte operation - std::size_t read_bytes = std::fread(buf, 1, static_cast(size), f); + const std::size_t read_bytes = std::fread(buf, 1, static_cast(size), f); if (size != static_cast(read_bytes)) { // Unexpected number of bytes read. Not sure if this is reflected in errno or not. ec = std::error_code(errno, std::system_category()); @@ -274,7 +274,7 @@ inline std::error_code fs_file_get_contents(const fs::path& file, std::string& p { std::uintmax_t size = 0; unsigned char* buf = nullptr; - std::error_code ec = fs_file_get_contents(file, buf, size, max_size); + const std::error_code ec = fs_file_get_contents(file, buf, size, max_size); if (ec) return ec; @@ -497,13 +497,13 @@ inline bool fs_path_is_writable(const fs::path& path, std::error_code& ec) } std::error_code ignored_ec; // ignore this error - bool is_directory = fs::is_directory(path, ignored_ec); - bool path_exists = fs::exists(path, ec); + const bool is_directory = fs::is_directory(path, ignored_ec); + const bool path_exists = fs::exists(path, ec); if (ec) { return false; } - fs::path dirname = (is_directory ? path : path.parent_path()); + const fs::path dirname = (is_directory ? path : path.parent_path()); #ifdef _WIN32 // win32 doesn't get access() (it just doesn't work with writing) diff --git a/src/libdebug/dchannel.cpp b/src/libdebug/dchannel.cpp index 8e543ef..d7da740 100644 --- a/src/libdebug/dchannel.cpp +++ b/src/libdebug/dchannel.cpp @@ -33,11 +33,11 @@ std::string debug_format_message(debug_level::flag level, const std::string& dom } if (format_flags.test(debug_format::level)) { // print level name - bool use_color = format_flags.test(debug_format::color); + const bool use_color = format_flags.test(debug_format::color); if (use_color) ret += debug_level::get_color_start(level); - std::string level_name = std::string("<") + debug_level::get_name(level) + ">"; + const std::string level_name = std::string("<") + debug_level::get_name(level) + ">"; ret += level_name + std::string(8 - level_name.size(), ' '); if (use_color) @@ -52,7 +52,7 @@ std::string debug_format_message(debug_level::flag level, const std::string& dom if (format_flags.test(debug_format::indent)) { - std::string spaces(static_cast(indent_level * 4), ' '); // indentation spaces + const std::string spaces(static_cast(indent_level * 4), ' '); // indentation spaces // replace all newlines with \n(indent-spaces) except for the last one. std::string::size_type oldpos = 0, pos = 0; diff --git a/src/libdebug/dcmdarg.cpp b/src/libdebug/dcmdarg.cpp index c18e773..f55dceb 100644 --- a/src/libdebug/dcmdarg.cpp +++ b/src/libdebug/dcmdarg.cpp @@ -91,7 +91,7 @@ static gboolean debug_internal_parse_levels([[maybe_unused]] const gchar* option if (!value) return FALSE; auto* args = static_cast(data); - std::string levels = value; + const std::string levels = value; hz::string_split(levels, ',', args->debug_levels, true); // will filter out invalid ones later return TRUE; @@ -143,7 +143,7 @@ static gboolean debug_internal_post_parse_func([[maybe_unused]] GOptionContext* if (args->verbosity_level > 4) args->levels_enabled.set(debug_level::dump); } - bool color_enabled = static_cast(args->debug_colorize); + const bool color_enabled = static_cast(args->debug_colorize); debug_internal::DebugState::DomainMap& domain_map = debug_internal::get_debug_state_ref().get_domain_map_ref(); diff --git a/src/libdebug/dout.cpp b/src/libdebug/dout.cpp index f1ddef7..d89c81d 100644 --- a/src/libdebug/dout.cpp +++ b/src/libdebug/dout.cpp @@ -29,13 +29,13 @@ std::ostream& debug_out(debug_level::flag level, const std::string& domain) auto level_map = dm.find(domain); if (level_map == dm.end()) { // no such domain // this is an internal error - std::string msg = "debug_out(): Debug state doesn't contain the requested domain: \"" + domain + "\"."; + const std::string msg = "debug_out(): Debug state doesn't contain the requested domain: \"" + domain + "\"."; throw debug_internal_error(msg.c_str()); } auto os = level_map->second.find(level); if (level_map == dm.end()) { - std::string msg = std::string("debug_out(): Debug state doesn't contain the requested level ") + + const std::string msg = std::string("debug_out(): Debug state doesn't contain the requested level ") + debug_level::get_name(level) + " in domain: \"" + domain + "\"."; // this is an internal error @@ -110,7 +110,7 @@ namespace debug_internal { // increase indentation level for all debug levels void debug_indent_inc(int by) { - int curr = debug_internal::get_debug_state_ref().get_indent_level(); + const int curr = debug_internal::get_debug_state_ref().get_indent_level(); debug_internal::get_debug_state_ref().set_indent_level(curr + by); } diff --git a/src/libdebug/dstate.cpp b/src/libdebug/dstate.cpp index 3e76525..d0a3f7e 100644 --- a/src/libdebug/dstate.cpp +++ b/src/libdebug/dstate.cpp @@ -44,7 +44,7 @@ namespace debug_internal { format_flags.set(debug_format::color); #endif - std::map levels = { + const std::map levels = { {debug_level::dump, levels_enabled.test(debug_level::dump) }, {debug_level::info, levels_enabled.test(debug_level::info) }, {debug_level::warn, levels_enabled.test(debug_level::warn) }, @@ -102,7 +102,7 @@ bool debug_register_domain(const std::string& domain) + "\"): Domain \"default\" doesn't exist.").c_str()); } - DebugState::LevelMap& def_level_map = def_iter->second; + const DebugState::LevelMap& def_level_map = def_iter->second; dm[domain] = DebugState::LevelMap(); DebugState::LevelMap& level_map = dm.find(domain)->second; diff --git a/src/libdebug/dstate.h b/src/libdebug/dstate.h index bb06138..fb84235 100644 --- a/src/libdebug/dstate.h +++ b/src/libdebug/dstate.h @@ -85,7 +85,7 @@ namespace debug_internal { { if (inside_begin_.empty()) throw debug_usage_error("DebugState::pop_inside_begin(): Begin / End stack underflow! Mismatched begin()/end()?"); - bool val = inside_begin_.top(); + const bool val = inside_begin_.top(); inside_begin_.pop(); return val; } diff --git a/src/libdebug/examples/example_libdebug.cpp b/src/libdebug/examples/example_libdebug.cpp index a25391f..ca8b118 100644 --- a/src/libdebug/examples/example_libdebug.cpp +++ b/src/libdebug/examples/example_libdebug.cpp @@ -78,9 +78,9 @@ int main_impl() )); - std::string something = "some thing"; + const std::string something = "some thing"; const char* obj = "obj"; - int op = 5; + const int op = 5; debug_out_dump("dom", "Dumping something: " << something << std::endl); diff --git a/src/rconfig/examples/example_rconfig.cpp b/src/rconfig/examples/example_rconfig.cpp index 9b5ab2b..930562b 100644 --- a/src/rconfig/examples/example_rconfig.cpp +++ b/src/rconfig/examples/example_rconfig.cpp @@ -48,7 +48,7 @@ int main() rconfig::set_data("app/int_var", 11); // override default. - int int_var = rconfig::get_data("app/int_value"); + const int int_var = rconfig::get_data("app/int_value"); std::cerr << "app/int_value: " << int_var << "\n"; std::cerr << "app/some_string2: " << rconfig::get_data("app/some_string2") << "\n"; diff --git a/src/test_all/test_all.cpp b/src/test_all/test_all.cpp index 21a63b8..6676911 100644 --- a/src/test_all/test_all.cpp +++ b/src/test_all/test_all.cpp @@ -29,7 +29,7 @@ int main(int argc, char* argv[]) debug_register_domain("hz"); debug_register_domain("rconfig"); - int result = Catch::Session().run( argc, argv ); + const int result = Catch::Session().run( argc, argv ); return result; }