logd: fix various clang-tidy issues
In order of severity:
1) Add a CHECK() that a pointer is not nullptr, where the analyzer
believes this is possible.
2) Add `final` appropriately to functions called from constructors.
3) Add missing cloexec flags.
4) Add missing `noexcept` and other subtle performance warnings
Test: build with clang-tidy
Change-Id: Ifd9a1299a51027a47382926b2224748b5750d6cf
diff --git a/logd/LogStatistics.h b/logd/LogStatistics.h
index 200c228..5f55802 100644
--- a/logd/LogStatistics.h
+++ b/logd/LogStatistics.h
@@ -128,9 +128,9 @@
if (++index < (ssize_t)len) {
size_t num = len - index - 1;
if (num) {
- memmove(&out_keys[index + 1], &out_keys[index], num * sizeof(out_keys[0]));
+ memmove(&out_keys[index + 1], &out_keys[index], num * sizeof(const TKey*));
memmove(&out_entries[index + 1], &out_entries[index],
- num * sizeof(out_entries[0]));
+ num * sizeof(const TEntry*));
}
out_keys[index] = &key;
out_entries[index] = &entry;
@@ -477,15 +477,15 @@
tagNameTable.sizeOf() +
(pidTable.size() * sizeof(pidTable_t::iterator)) +
(tagTable.size() * sizeof(tagTable_t::iterator));
- for (auto it : pidTable) {
+ for (const auto& it : pidTable) {
const char* name = it.second.name();
if (name) size += strlen(name) + 1;
}
- for (auto it : tidTable) {
+ for (const auto& it : tidTable) {
const char* name = it.second.name();
if (name) size += strlen(name) + 1;
}
- for (auto it : tagNameTable) {
+ for (const auto& it : tagNameTable) {
size += sizeof(std::string);
size_t len = it.first.size();
// Account for short string optimization: if the string's length is <= 22 bytes for 64
@@ -505,7 +505,7 @@
}
public:
- LogStatistics(bool enable_statistics);
+ explicit LogStatistics(bool enable_statistics);
void AddTotal(log_id_t log_id, uint16_t size) EXCLUDES(lock_);
void Add(const LogStatisticsElement& entry) EXCLUDES(lock_);