Clang-tidy updates for 19
Update to add new checks that are now available to us. Fix the minor
issues we have. A few of our checks that we previously had enabled have
been renamed, so remove those from the file as well.
Change-Id: Idbbfc3cb7ba42ac780e557554d7ae8ab190e7551
Signed-off-by: Ed Tanous <etanous@nvidia.com>
diff --git a/.clang-tidy b/.clang-tidy
index 8092fdc..cb24463 100644
--- a/.clang-tidy
+++ b/.clang-tidy
@@ -11,6 +11,7 @@
bugprone-chained-comparison,
bugprone-compare-pointer-to-member-virtual-function,
bugprone-copy-constructor-init,
+bugprone-crtp-constructor-accessibility,
bugprone-dangling-handle,
bugprone-dynamic-static-initializers,
bugprone-empty-catch,
@@ -41,9 +42,11 @@
bugprone-not-null-terminated-result,
bugprone-optional-value-conversion,
bugprone-parent-virtual-call,
+bugprone-pointer-arithmetic-on-polymorphic-object,
bugprone-posix-return,
bugprone-redundant-branch-condition,
bugprone-reserved-identifier,
+bugprone-return-const-ref-from-parameter,
bugprone-shared-ptr-array-mismatch,
bugprone-signal-handler,
bugprone-signed-char-misuse,
@@ -63,6 +66,7 @@
bugprone-suspicious-realloc-usage,
bugprone-suspicious-semicolon,
bugprone-suspicious-string-compare,
+bugprone-suspicious-stringview-data-usage,
bugprone-swapped-arguments,
bugprone-switch-missing-default-case,
bugprone-terminating-continue,
@@ -82,6 +86,7 @@
bugprone-virtual-near-miss,
cert-con36-c,
cert-con54-cpp,
+cert-ctr56-cpp,
cert-dcl03-c,
cert-dcl16-c,
cert-dcl21-cpp,
@@ -138,6 +143,7 @@
clang-analyzer-core.uninitialized.CapturedBlockVariable,
clang-analyzer-core.uninitialized.NewArraySize,
clang-analyzer-core.uninitialized.UndefReturn,
+clang-analyzer-cplusplus.ArrayDelete,
clang-analyzer-cplusplus.InnerPointer,
clang-analyzer-cplusplus.Move,
clang-analyzer-cplusplus.NewDelete,
@@ -165,6 +171,7 @@
clang-analyzer-optin.osx.cocoa.localizability.NonLocalizedStringChecker,
clang-analyzer-optin.performance.GCDAntipattern,
clang-analyzer-optin.performance.Padding,
+clang-analyzer-optin.taint.TaintedAlloc,
clang-analyzer-optin.portability.UnixAPI,
clang-analyzer-osx.API,
clang-analyzer-osx.MIG,
@@ -198,6 +205,8 @@
clang-analyzer-osx.coreFoundation.containers.OutOfBounds,
clang-analyzer-osx.coreFoundation.containers.PointerSizedValues,
clang-analyzer-security.FloatLoopCounter,
+clang-analyzer-security.PutenvStackArray,
+clang-analyzer-security.SetgidSetuidOrder,
clang-analyzer-security.cert.env.InvalidPtr,
clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling,
clang-analyzer-security.insecureAPI.SecuritySyntaxChecker,
@@ -214,6 +223,7 @@
clang-analyzer-security.insecureAPI.strcpy,
clang-analyzer-security.insecureAPI.vfork,
clang-analyzer-unix.API,
+clang-analyzer-unix.BlockInCriticalSection,
clang-analyzer-unix.DynamicMemoryModeling,
clang-analyzer-unix.Errno,
clang-analyzer-unix.Malloc,
@@ -231,6 +241,8 @@
clang-analyzer-webkit.NoUncountedMemberChecker,
clang-analyzer-webkit.RefCntblBaseVirtualDtor,
clang-analyzer-webkit.UncountedLambdaCapturesChecker,
+concurrency-mt-unsafe,
+concurrency-thread-canceltype-asynchronous,
cppcoreguidelines-avoid-c-arrays,
cppcoreguidelines-avoid-capturing-lambda-coroutines,
cppcoreguidelines-avoid-goto,
@@ -266,6 +278,7 @@
cppcoreguidelines-special-member-functions,
google-explicit-constructor,
misc-coroutine-hostile-raii,
+misc-definitions-in-headers,
misc-header-include-cycle,
misc-include-cleaner,
misc-misleading-bidirectional,
@@ -337,7 +350,6 @@
readability-convert-member-functions-to-static,
readability-delete-null-pointer,
readability-duplicate-include,
-readability-deleted-default,
readability-else-after-return,
readability-function-size,
readability-identifier-naming,
@@ -348,8 +360,8 @@
readability-misleading-indentation,
readability-misplaced-array-index,
readability-named-parameter,
-readability-operators-representation,
readability-non-const-parameter,
+readability-operators-representation,
readability-qualified-auto,
readability-redundant-access-specifiers,
readability-redundant-casting,
@@ -370,7 +382,8 @@
readability-string-compare,
readability-suspicious-call-argument,
readability-uniqueptr-delete-release,
-readability-uppercase-literal-suffix'
+readability-uppercase-literal-suffix,
+readability-use-std-min-max'
WarningsAsErrors: '*'
HeaderFilterRegex: '.*'
diff --git a/http/routing/ruleparametertraits.hpp b/http/routing/ruleparametertraits.hpp
index 949f390..3ed9aa0 100644
--- a/http/routing/ruleparametertraits.hpp
+++ b/http/routing/ruleparametertraits.hpp
@@ -13,6 +13,11 @@
template <typename T>
struct RuleParameterTraits
{
+ private:
+ RuleParameterTraits() = default;
+ friend T;
+
+ public:
using self_t = T;
WebSocketRule& websocket()
{
diff --git a/include/obmc_console.hpp b/include/obmc_console.hpp
index 81303e5..15c44de 100644
--- a/include/obmc_console.hpp
+++ b/include/obmc_console.hpp
@@ -200,8 +200,7 @@
int fd = dup(unixfd);
if (fd == -1)
{
- BMCWEB_LOG_ERROR("Failed to dup the DBUS unixfd error: {}",
- strerror(errno));
+ BMCWEB_LOG_ERROR("Failed to dup the DBUS unixfd error");
conn.close("Internal error");
return;
}
diff --git a/redfish-core/include/registries.hpp b/redfish-core/include/registries.hpp
index ce6d7b8..a465d6e 100644
--- a/redfish-core/include/registries.hpp
+++ b/redfish-core/include/registries.hpp
@@ -73,7 +73,7 @@
ret += msg.substr(0, stringIndex);
msg.remove_prefix(stringIndex + 1);
size_t number = 0;
- auto it = std::from_chars(msg.data(), &*msg.end(), number);
+ auto it = std::from_chars(&*msg.begin(), &*msg.end(), number);
if (it.ec != std::errc())
{
return "";
diff --git a/redfish-core/lib/manager_logservices_journal.hpp b/redfish-core/lib/manager_logservices_journal.hpp
index 8bc1549..acab53c 100644
--- a/redfish-core/lib/manager_logservices_journal.hpp
+++ b/redfish-core/lib/manager_logservices_journal.hpp
@@ -20,7 +20,7 @@
namespace redfish
{
-inline int getJournalMetadata(sd_journal* journal, std::string_view field,
+inline int getJournalMetadata(sd_journal* journal, const char* field,
std::string_view& contents)
{
const char* data = nullptr;
@@ -30,7 +30,7 @@
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
const void** dataVoid = reinterpret_cast<const void**>(&data);
- ret = sd_journal_get_data(journal, field.data(), dataVoid, &length);
+ ret = sd_journal_get_data(journal, field, dataVoid, &length);
if (ret < 0)
{
return ret;
@@ -41,19 +41,23 @@
return ret;
}
-inline int getJournalMetadataInt(sd_journal* journal, std::string_view field,
- const int& base, long int& contents)
+inline int getJournalMetadataInt(sd_journal* journal, const char* field,
+ const int base, long int& contents)
{
- int ret = 0;
std::string_view metadata;
// Get the metadata from the requested field of the journal entry
- ret = getJournalMetadata(journal, field, metadata);
+ int ret = getJournalMetadata(journal, field, metadata);
if (ret < 0)
{
return ret;
}
- contents = strtol(metadata.data(), nullptr, base);
- return ret;
+ std::from_chars_result res =
+ std::from_chars(&*metadata.begin(), &*metadata.end(), contents, base);
+ if (res.ec != std::error_code{} || res.ptr != &*metadata.end())
+ {
+ return -1;
+ }
+ return 0;
}
inline bool getEntryTimestamp(sd_journal* journal, std::string& entryTimestamp)
@@ -63,7 +67,7 @@
ret = sd_journal_get_realtime_usec(journal, ×tamp);
if (ret < 0)
{
- BMCWEB_LOG_ERROR("Failed to read entry timestamp: {}", strerror(-ret));
+ BMCWEB_LOG_ERROR("Failed to read entry timestamp: {}", ret);
return false;
}
entryTimestamp = redfish::time_utils::getDateTimeUintUs(timestamp);
@@ -88,8 +92,7 @@
ret = getJournalMetadata(journal, "SYSLOG_IDENTIFIER", syslogID);
if (ret < 0)
{
- BMCWEB_LOG_DEBUG("Failed to read SYSLOG_IDENTIFIER field: {}",
- strerror(-ret));
+ BMCWEB_LOG_DEBUG("Failed to read SYSLOG_IDENTIFIER field: {}", ret);
}
if (!syslogID.empty())
{
@@ -100,7 +103,7 @@
ret = getJournalMetadata(journal, "MESSAGE", msg);
if (ret < 0)
{
- BMCWEB_LOG_ERROR("Failed to read MESSAGE field: {}", strerror(-ret));
+ BMCWEB_LOG_ERROR("Failed to read MESSAGE field: {}", ret);
return false;
}
message += std::string(msg);
@@ -110,7 +113,7 @@
ret = getJournalMetadataInt(journal, "PRIORITY", 10, severity);
if (ret < 0)
{
- BMCWEB_LOG_DEBUG("Failed to read PRIORITY field: {}", strerror(-ret));
+ BMCWEB_LOG_DEBUG("Failed to read PRIORITY field: {}", ret);
}
// Get the Created time from the timestamp
@@ -294,7 +297,7 @@
int ret = sd_journal_open(&journalTmp, SD_JOURNAL_LOCAL_ONLY);
if (ret < 0)
{
- BMCWEB_LOG_ERROR("failed to open journal: {}", strerror(-ret));
+ BMCWEB_LOG_ERROR("failed to open journal: {}", ret);
messages::internalError(asyncResp->res);
return;
}
@@ -401,7 +404,7 @@
int ret = sd_journal_open(&journalTmp, SD_JOURNAL_LOCAL_ONLY);
if (ret < 0)
{
- BMCWEB_LOG_ERROR("failed to open journal: {}", strerror(-ret));
+ BMCWEB_LOG_ERROR("failed to open journal: {}", ret);
messages::internalError(asyncResp->res);
return;
}