From 531c35158cd4e3fc6c6f0471a3e9dd836c617763 Mon Sep 17 00:00:00 2001 From: Timothy Stack Date: Sun, 3 Apr 2022 22:10:20 -0700 Subject: [PATCH] [tidy] some more tidying --- .clang-tidy | 30 ++++++++++++++++++------------ src/attr_line.hh | 3 ++- src/hotkeys.cc | 2 +- src/logfile_sub_source.cc | 20 +++++++++++++------- test/test_date_time_scanner.cc | 10 ++++++---- 5 files changed, 40 insertions(+), 25 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index b4598a3e..138dd8a8 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,18 +1,24 @@ --- # Enable ALL the things! Except not really # misc-non-private-member-variables-in-classes: the options don't do anything -Checks: "*,\ - -google-readability-todo,\ - -altera-unroll-loops,\ - -altera-id-dependent-backward-branch,\ - -altera-struct-pack-align,\ - -fuchsia-*,\ - fuchsia-multiple-inheritance,\ - -llvm-header-guard,\ - -llvm-include-order,\ - -llvmlibc-*,\ - -modernize-use-trailing-return-type,\ - -misc-non-private-member-variables-in-classes" +Checks: > + *, + -google-readability-todo, + -altera-unroll-loops, + -altera-id-dependent-backward-branch, + -altera-struct-pack-align, + -fuchsia-*, + fuchsia-multiple-inheritance, + -llvm-header-guard, + -llvm-include-order, + -llvmlibc-*, + -modernize-use-trailing-return-type, + -misc-non-private-member-variables-in-classes, + -cppcoreguidelines-pro-type-vararg, + -hicpp-vararg, + -cppcoreguidelines-avoid-c-arrays, + -hicpp-avoid-c-arrays, + -modernize-avoid-c-arrays WarningsAsErrors: '' CheckOptions: - key: 'bugprone-argument-comment.StrictMode' diff --git a/src/attr_line.hh b/src/attr_line.hh index 2a33e083..f6c52db7 100644 --- a/src/attr_line.hh +++ b/src/attr_line.hh @@ -169,7 +169,8 @@ template struct string_attr_wrapper { explicit string_attr_wrapper(const string_attr* sa) : saw_string_attr(sa) {} - const T& get() const + template + std::enable_if_t::value, const U&> get() const { return this->saw_string_attr->sa_value.template get(); } diff --git a/src/hotkeys.cc b/src/hotkeys.cc index 1a367ffc..ff468bd9 100644 --- a/src/hotkeys.cc +++ b/src/hotkeys.cc @@ -95,7 +95,7 @@ public: false); }; - std::string to_string(const struct line_range& lr) + std::string to_string(const struct line_range& lr) const { const char* start = this->lh_msg_buffer.get_data(); diff --git a/src/logfile_sub_source.cc b/src/logfile_sub_source.cc index 5f09ed64..738bfce5 100644 --- a/src/logfile_sub_source.cc +++ b/src/logfile_sub_source.cc @@ -1464,12 +1464,18 @@ logfile_sub_source::eval_sql_filter(sqlite3_stmt* stmt, continue; } if (strcmp(name, ":log_body") == 0) { - auto iter = find_string_attr(sa, &SA_BODY); - sqlite3_bind_text(stmt, - lpc + 1, - &(sbr.get_data()[iter->sa_range.lr_start]), - iter->sa_range.length(), - SQLITE_STATIC); + auto body_attr_opt = get_string_attr(sa, SA_BODY); + if (body_attr_opt) { + auto& sar = body_attr_opt.value().saw_string_attr->sa_range; + + sqlite3_bind_text(stmt, + lpc + 1, + sbr.get_data_at(sar.lr_start), + sar.length(), + SQLITE_STATIC); + } else { + sqlite3_bind_null(stmt, lpc + 1); + } continue; } if (strcmp(name, ":log_raw_text") == 0) { @@ -1485,7 +1491,7 @@ logfile_sub_source::eval_sql_filter(sqlite3_stmt* stmt, } continue; } - for (auto& lv : values) { + for (const auto& lv : values) { if (lv.lv_meta.lvm_name != &name[1]) { continue; } diff --git a/test/test_date_time_scanner.cc b/test/test_date_time_scanner.cc index 168e5fda..40fe9e20 100644 --- a/test/test_date_time_scanner.cc +++ b/test/test_date_time_scanner.cc @@ -43,12 +43,14 @@ static const char* GOOD_TIMES[] = { "05/18/2018 12:00:53 AM", }; -static const char* BAD_TIMES[] = {"1-2-3 1:2:3", +static const char* BAD_TIMES[] = { + "1-2-3 1:2:3", - "2013-22-01 12:01:22", - "2013-00-01 12:01:22", + "2013-22-01 12:01:22", + "2013-00-01 12:01:22", - "@4000000043"}; + "@4000000043", +}; int main(int argc, char* argv[])