diff --git a/gsmartcontrol/.clang-tidy b/gsmartcontrol/.clang-tidy index 06d475b..bd6f85f 100644 --- a/gsmartcontrol/.clang-tidy +++ b/gsmartcontrol/.clang-tidy @@ -1,5 +1,5 @@ --- -Checks: 'clang-diagnostic-*,clang-analyzer-*,-*,bugprone-*,cppcoreguidelines-*,clang-analyzer-*,misc-*,performance-*,readability-*-cppcoreguidelines-pro-type-const-cast,-cppcoreguidelines-pro-type-reinterpret-cast,-readability-function-size,-readability-simplify-boolean-expr,-cppcoreguidelines-pro-type-cstyle-cast,-performance-inefficient-string-concatenation,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-cppcoreguidelines-pro-type-vararg,-cppguidelines-pro-bounds-pointer-arithmetic,-cppguidelines-pro-bounds-constant-array-index' +Checks: 'clang-diagnostic-*,clang-analyzer-*,-*,bugprone-*,cppcoreguidelines-*,clang-analyzer-*,misc-*,performance-*,readability-*-cppcoreguidelines-pro-type-const-cast,-cppcoreguidelines-pro-type-reinterpret-cast,-readability-function-size,-readability-simplify-boolean-expr,-cppcoreguidelines-pro-type-cstyle-cast,-performance-inefficient-string-concatenation,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-cppcoreguidelines-pro-type-vararg,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-pro-bounds-constant-array-index' WarningsAsErrors: '' HeaderFilterRegex: '' AnalyzeTemporaryDtors: true diff --git a/gsmartcontrol/TODO b/gsmartcontrol/TODO index bcaf921..d0b77ad 100644 --- a/gsmartcontrol/TODO +++ b/gsmartcontrol/TODO @@ -50,15 +50,12 @@ Use std::from_chars() in string_is_numeric_impl_classic_locale() (gcc 8) std::string setters -> no const&, use std::move. same for std::vector -switch -> static const std::map for iter -> for auto push_back -> static vector Should StorageProperty contain also value_uinteger? Check TODOs -Test with clang-tidy - diff --git a/gsmartcontrol/src/applib/storage_property_descr.cpp b/gsmartcontrol/src/applib/storage_property_descr.cpp index d4d217a..9bd6386 100644 --- a/gsmartcontrol/src/applib/storage_property_descr.cpp +++ b/gsmartcontrol/src/applib/storage_property_descr.cpp @@ -1773,73 +1773,75 @@ WarningLevel storage_property_autoset_warning(StorageProperty& p) case StorageProperty::SubSection::devstat: { - const auto& statistic = p.get_value(); + if (p.is_value_type()) { + const auto& statistic = p.get_value(); - if (name_match(p, "Pending Error Count") && statistic.value_int > 0) { - w = WarningLevel::notice; - reason = "The drive is reporting surface errors. This could be an indication of future failures and/or potential data loss in bad sectors."; + if (name_match(p, "Pending Error Count") && statistic.value_int > 0) { + w = WarningLevel::notice; + reason = "The drive is reporting surface errors. This could be an indication of future failures and/or potential data loss in bad sectors."; - // "Workload Utilization" is either normalized, or encodes several values, so we can't use it. -/* - } else if (name_match(p, "Workload Utilization") && statistic.value_int >= 50) { - w = WarningLevel::notice; - reason = "The drive has less than half of its estimated life left."; + // "Workload Utilization" is either normalized, or encodes several values, so we can't use it. + /* + } else if (name_match(p, "Workload Utilization") && statistic.value_int >= 50) { + w = WarningLevel::notice; + reason = "The drive has less than half of its estimated life left."; - } else if (name_match(p, "Workload Utilization") && statistic.value_int >= 100) { - w = WarningLevel::warning; - reason = "The drive is past its estimated lifespan."; -*/ + } else if (name_match(p, "Workload Utilization") && statistic.value_int >= 100) { + w = WarningLevel::warning; + reason = "The drive is past its estimated lifespan."; + */ - } else if (name_match(p, "Utilization Usage Rate") && statistic.value_int >= 50) { - w = WarningLevel::notice; - reason = "The drive has less than half of its estimated life left."; + } else if (name_match(p, "Utilization Usage Rate") && statistic.value_int >= 50) { + w = WarningLevel::notice; + reason = "The drive has less than half of its estimated life left."; - } else if (name_match(p, "Utilization Usage Rate") && statistic.value_int >= 100) { - w = WarningLevel::warning; - reason = "The drive is past its estimated lifespan."; + } else if (name_match(p, "Utilization Usage Rate") && statistic.value_int >= 100) { + w = WarningLevel::warning; + reason = "The drive is past its estimated lifespan."; - } else if (name_match(p, "Number of Reallocated Logical Sectors") && !statistic.is_normalized() && statistic.value_int > 0) { - w = WarningLevel::notice; - reason = "The drive is reporting surface errors. This could be an indication of future failures and/or potential data loss in bad sectors."; + } else if (name_match(p, "Number of Reallocated Logical Sectors") && !statistic.is_normalized() && statistic.value_int > 0) { + w = WarningLevel::notice; + reason = "The drive is reporting surface errors. This could be an indication of future failures and/or potential data loss in bad sectors."; - } else if (name_match(p, "Number of Reallocated Logical Sectors") && statistic.is_normalized() && statistic.value_int <= 0) { - w = WarningLevel::warning; - reason = "The drive is reporting surface errors. This could be an indication of future failures and/or potential data loss in bad sectors."; + } else if (name_match(p, "Number of Reallocated Logical Sectors") && statistic.is_normalized() && statistic.value_int <= 0) { + w = WarningLevel::warning; + reason = "The drive is reporting surface errors. This could be an indication of future failures and/or potential data loss in bad sectors."; - } else if (name_match(p, "Number of Mechanical Start Failures") && statistic.value_int > 0) { - w = WarningLevel::notice; - reason = "The drive is reporting mechanical errors."; + } else if (name_match(p, "Number of Mechanical Start Failures") && statistic.value_int > 0) { + w = WarningLevel::notice; + reason = "The drive is reporting mechanical errors."; - } else if (name_match(p, "Number of Realloc. Candidate Logical Sectors") && statistic.value_int > 0) { - w = WarningLevel::notice; - reason = "The drive is reporting surface errors. This could be an indication of future failures and/or potential data loss in bad sectors."; + } else if (name_match(p, "Number of Realloc. Candidate Logical Sectors") && statistic.value_int > 0) { + w = WarningLevel::notice; + reason = "The drive is reporting surface errors. This could be an indication of future failures and/or potential data loss in bad sectors."; - } else if (name_match(p, "Number of Reported Uncorrectable Errors") && statistic.value_int > 0) { - w = WarningLevel::notice; - reason = "The drive is reporting surface errors. This could be an indication of future failures and/or potential data loss in bad sectors."; + } else if (name_match(p, "Number of Reported Uncorrectable Errors") && statistic.value_int > 0) { + w = WarningLevel::notice; + reason = "The drive is reporting surface errors. This could be an indication of future failures and/or potential data loss in bad sectors."; - } else if (name_match(p, "Current Temperature") && statistic.value_int > 50) { - w = WarningLevel::notice; - reason = "The temperature of the drive is higher than 50 degrees Celsius. " - "This may shorten its lifespan and cause damage under severe load. Please install a cooling solution."; + } else if (name_match(p, "Current Temperature") && statistic.value_int > 50) { + w = WarningLevel::notice; + reason = "The temperature of the drive is higher than 50 degrees Celsius. " + "This may shorten its lifespan and cause damage under severe load. Please install a cooling solution."; - } else if (name_match(p, "Time in Over-Temperature") && statistic.value_int > 0) { - w = WarningLevel::notice; - reason = "The temperature of the drive is or was over the manufacturer-specified maximum. " - "This may have shortened its lifespan and caused damage. Please install a cooling solution."; + } else if (name_match(p, "Time in Over-Temperature") && statistic.value_int > 0) { + w = WarningLevel::notice; + reason = "The temperature of the drive is or was over the manufacturer-specified maximum. " + "This may have shortened its lifespan and caused damage. Please install a cooling solution."; - } else if (name_match(p, "Time in Under-Temperature") && statistic.value_int > 0) { - w = WarningLevel::notice; - reason = "The temperature of the drive is or was under the manufacturer-specified minimum. " - "This may have shortened its lifespan and caused damage. Please operate the drive within manufacturer-specified temperature range."; + } else if (name_match(p, "Time in Under-Temperature") && statistic.value_int > 0) { + w = WarningLevel::notice; + reason = "The temperature of the drive is or was under the manufacturer-specified minimum. " + "This may have shortened its lifespan and caused damage. Please operate the drive within manufacturer-specified temperature range."; - } else if (name_match(p, "Percentage Used Endurance Indicator") && statistic.value_int >= 50) { - w = WarningLevel::notice; - reason = "The drive has less than half of its estimated life left."; + } else if (name_match(p, "Percentage Used Endurance Indicator") && statistic.value_int >= 50) { + w = WarningLevel::notice; + reason = "The drive has less than half of its estimated life left."; - } else if (name_match(p, "Percentage Used Endurance Indicator") && statistic.value_int >= 100) { - w = WarningLevel::warning; - reason = "The drive is past its estimated lifespan."; + } else if (name_match(p, "Percentage Used Endurance Indicator") && statistic.value_int >= 100) { + w = WarningLevel::warning; + reason = "The drive is past its estimated lifespan."; + } } break; diff --git a/gsmartcontrol/src/hz/format_unit_example.cpp b/gsmartcontrol/src/hz/format_unit_example.cpp index c360c9d..9082aa2 100644 --- a/gsmartcontrol/src/hz/format_unit_example.cpp +++ b/gsmartcontrol/src/hz/format_unit_example.cpp @@ -45,20 +45,17 @@ int main() std::cerr << hz::format_size(uint64_t(1000204886016ULL), true) << "\n"; // common size of 1 TiB hdd in decimal + using namespace std::literals; + using days = std::chrono::duration, std::chrono::hours::period>>; - const uint64_t min_size = 60; - const uint64_t hour_size = min_size * 60; - const uint64_t day_size = hour_size * 24; - - std::cerr << hz::format_time_length(5) << "\n"; // 5 sec - std::cerr << hz::format_time_length(uint64_t(5.5 * min_size)) << "\n"; // 5.5 min - std::cerr << hz::format_time_length(130 * min_size) << "\n"; // 130 min - std::cerr << hz::format_time_length(uint64_t(5.5 * hour_size)) << "\n"; // 5.5 hours - std::cerr << hz::format_time_length(uint64_t(24.33 * hour_size)) << "\n"; // 24 hours, 20 minutes - std::cerr << hz::format_time_length(130 * hour_size + 30 * min_size) << "\n"; // 130.5 hours - std::cerr << hz::format_time_length(5 * day_size + 15 * hour_size + 30 * min_size) << "\n"; // 5 days, 15 hours, 30 minutes - std::cerr << hz::format_time_length(20 * day_size - 8 * hour_size) << "\n"; // 19 days, 16 hours - + std::cerr << hz::format_time_length(5s) << "\n"; // 5 sec + std::cerr << hz::format_time_length(5min + 30s) << "\n"; // 5.5 min + std::cerr << hz::format_time_length(130min) << "\n"; // 130 min + std::cerr << hz::format_time_length(5h + 30min) << "\n"; // 5.5 hours + std::cerr << hz::format_time_length(24h + 20min) << "\n"; // 24 hours, 20 minutes + std::cerr << hz::format_time_length(130h + 30min) << "\n"; // 130.5 hours + std::cerr << hz::format_time_length(days(5) + 15h + 30min) << "\n"; // 5 days, 15 hours, 30 minutes + std::cerr << hz::format_time_length(days(20) - 8h) << "\n"; // 19 days, 16 hours return 0; } diff --git a/gsmartcontrol/src/hz/string_num.h b/gsmartcontrol/src/hz/string_num.h index 93f2043..b51a01b 100644 --- a/gsmartcontrol/src/hz/string_num.h +++ b/gsmartcontrol/src/hz/string_num.h @@ -376,7 +376,14 @@ namespace internal { ss << std::setfill('0') << std::internal << std::setw(static_cast((sizeof(T) * 2) + 2)); } - ss << std::showbase << std::setbase(base) << number; + ss << std::showbase << std::setbase(base); + + if constexpr(std::is_same_v || std::is_same_v || std::is_same_v + || std::is_same_v || std::is_same_v || std::is_same_v) { + ss << static_cast(number); // avoid printing them as characters + } else { + ss << number; + } return ss.str(); } diff --git a/gsmartcontrol/src/json/Makefile.in b/gsmartcontrol/src/json/Makefile.in index e279c41..eb4978d 100644 --- a/gsmartcontrol/src/json/Makefile.in +++ b/gsmartcontrol/src/json/Makefile.in @@ -265,8 +265,8 @@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ AM_CPPFLAGS = $(all_includes) METASOURCES = AUTO -noinst_HEADERS = picojson.h -noinst_DATA = picojson_version.txt +noinst_HEADERS = json.hpp +noinst_DATA = LICENSE.MIT json_version.txt all: all-am .SUFFIXES: diff --git a/gsmartcontrol/src/libdebug/libdebug_example.cpp b/gsmartcontrol/src/libdebug/libdebug_example.cpp index bde7f3a..36d8af0 100644 --- a/gsmartcontrol/src/libdebug/libdebug_example.cpp +++ b/gsmartcontrol/src/libdebug/libdebug_example.cpp @@ -70,7 +70,7 @@ int main(int argc, char *argv[]) debug_set_enabled("dom", debug_level::dump, false); debug_set_format("dom", debug_level::info, - (!debug_get_formats("dom")[debug_level::info].none() & !debug_format::color) | debug_format::datetime); + (!debug_get_formats("dom")[debug_level::info].none() & ~debug_format::color) | debug_format::datetime); std::string something = "some thing";