From 320a65f77ccb75abeb2c04c8a20e2aa74ab8b217 Mon Sep 17 00:00:00 2001 From: Alex Kremer Date: Tue, 10 Mar 2026 08:34:27 +0000 Subject: [PATCH] chore: Enable clang-tidy `bugprone-suspicious-stringview-data-usage` check (#6467) --- .clang-tidy | 2 +- src/libxrpl/beast/core/CurrentThreadName.cpp | 5 +++-- src/test/core/Config_test.cpp | 4 ++-- src/test/rpc/AccountInfo_test.cpp | 5 +++-- src/xrpld/overlay/detail/OverlayImpl.cpp | 2 +- 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index fb702375ea..4f7280b958 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -54,6 +54,7 @@ Checks: "-*, bugprone-suspicious-realloc-usage, bugprone-suspicious-semicolon, bugprone-suspicious-string-compare, + bugprone-suspicious-stringview-data-usage, bugprone-swapped-arguments, bugprone-terminating-continue, bugprone-throw-keyword-missing, @@ -95,7 +96,6 @@ Checks: "-*, # bugprone-reserved-identifier, # bugprone-move-forwarding-reference, # bugprone-switch-missing-default-case, -# bugprone-suspicious-stringview-data-usage, # bugprone-optional-value-conversion, # bugprone-too-small-loop-variable, # bugprone-unused-return-value, diff --git a/src/libxrpl/beast/core/CurrentThreadName.cpp b/src/libxrpl/beast/core/CurrentThreadName.cpp index b63911e9f4..8e54a74e4d 100644 --- a/src/libxrpl/beast/core/CurrentThreadName.cpp +++ b/src/libxrpl/beast/core/CurrentThreadName.cpp @@ -62,7 +62,8 @@ namespace beast::detail { inline void setCurrentThreadNameImpl(std::string_view name) { - pthread_setname_np(name.data()); + // The string is assumed to be null terminated + pthread_setname_np(name.data()); // NOLINT(bugprone-suspicious-stringview-data-usage) } } // namespace beast::detail @@ -85,7 +86,7 @@ setCurrentThreadNameImpl(std::string_view name) sizeof(boundedName), "%.*s", static_cast(maxThreadNameLength), - name.data()); + name.data()); // NOLINT(bugprone-suspicious-stringview-data-usage) pthread_setname_np(pthread_self(), boundedName); diff --git a/src/test/core/Config_test.cpp b/src/test/core/Config_test.cpp index 0ce457ec89..dd6e0377d5 100644 --- a/src/test/core/Config_test.cpp +++ b/src/test/core/Config_test.cpp @@ -1280,7 +1280,7 @@ r.ripple.com:51235 for (auto const& t : tests) { Section s; - s.append(t.line.data()); + s.append(std::string(t.line)); BEAST_EXPECT(s.had_trailing_comments() == t.had_comment); if (t.field.empty()) { @@ -1289,7 +1289,7 @@ r.ripple.com:51235 else { std::string field; - BEAST_EXPECTS(set(field, t.field.data(), s), t.line); + BEAST_EXPECTS(set(field, std::string(t.field), s), t.line); BEAST_EXPECTS(field == t.expect, t.line); } } diff --git a/src/test/rpc/AccountInfo_test.cpp b/src/test/rpc/AccountInfo_test.cpp index a67eef996d..76079a9023 100644 --- a/src/test/rpc/AccountInfo_test.cpp +++ b/src/test/rpc/AccountInfo_test.cpp @@ -502,11 +502,12 @@ public: Json::Value params; params[jss::account] = account.human(); auto const info = env.rpc("json", "account_info", to_string(params)); + auto const name = std::string(fName); std::optional res; if (info[jss::result][jss::status] == "success" && - info[jss::result][jss::account_flags].isMember(fName.data())) - res.emplace(info[jss::result][jss::account_flags][fName.data()].asBool()); + info[jss::result][jss::account_flags].isMember(name)) + res.emplace(info[jss::result][jss::account_flags][name].asBool()); return res; }; diff --git a/src/xrpld/overlay/detail/OverlayImpl.cpp b/src/xrpld/overlay/detail/OverlayImpl.cpp index 55f45e727e..4379f1b265 100644 --- a/src/xrpld/overlay/detail/OverlayImpl.cpp +++ b/src/xrpld/overlay/detail/OverlayImpl.cpp @@ -825,7 +825,7 @@ OverlayImpl::processValidatorList(http_request_type const& req, Handoff& handoff // return the most recent validator list for that key. constexpr std::string_view prefix("/vl/"); - if (!req.target().starts_with(prefix.data()) || !setup_.vlEnabled) + if (!req.target().starts_with(prefix) || !setup_.vlEnabled) return false; std::uint32_t version = 1;