From: Francesco Chemolli <5175948+kinkie@users.noreply.github.com> Date: Tue, 19 Mar 2024 01:55:14 +0000 (+0000) Subject: NoNewGlobals: HttpUpgradeProtocolAccess::ProtoOther (#1745) X-Git-Tag: SQUID_7_0_1~167 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f8de3912c8d58e2ae3aefb8db311d46258a21c7b;p=thirdparty%2Fsquid.git NoNewGlobals: HttpUpgradeProtocolAccess::ProtoOther (#1745) Detected by Coverity. CID 1554674: Initialization or destruction ordering is unspecified (GLOBAL_INIT_ORDER). --- diff --git a/src/HttpUpgradeProtocolAccess.cc b/src/HttpUpgradeProtocolAccess.cc index 6bd099c564..ff4d572b48 100644 --- a/src/HttpUpgradeProtocolAccess.cc +++ b/src/HttpUpgradeProtocolAccess.cc @@ -17,8 +17,6 @@ #include -const SBuf HttpUpgradeProtocolAccess::ProtoOther("OTHER"); - ProtocolView::ProtocolView(const char * const start, const size_t len): ProtocolView(SBuf(start, len)) { @@ -51,9 +49,9 @@ HttpUpgradeProtocolAccess::configureGuard(ConfigParser &parser) { const auto rawProto = parser.NextToken(); if (!rawProto) - throw TextException(ToSBuf("expected a protocol name or ", ProtoOther), Here()); + throw TextException(ToSBuf("expected a protocol name or ", ProtoOther()), Here()); - if (ProtoOther.cmp(rawProto) == 0) { + if (ProtoOther().cmp(rawProto) == 0) { aclParseAccessLine(cfg_directive, parser, &other); return; } diff --git a/src/HttpUpgradeProtocolAccess.h b/src/HttpUpgradeProtocolAccess.h index ae8a02ee11..a310cd86fa 100644 --- a/src/HttpUpgradeProtocolAccess.h +++ b/src/HttpUpgradeProtocolAccess.h @@ -82,7 +82,7 @@ private: typedef std::deque NamedGuards; /// pseudonym to specify rules for "all other protocols" - static const SBuf ProtoOther; + inline static const SBuf &ProtoOther(); /// rules governing upgrades to explicitly named protocols NamedGuards namedGuards; @@ -98,7 +98,7 @@ HttpUpgradeProtocolAccess::forEach(const Visitor &visitor) const for (const auto &namedGuard: namedGuards) visitor(namedGuard.protocol, namedGuard.guard); if (other) - visitor(ProtoOther, other); + visitor(ProtoOther(), other); } template @@ -114,7 +114,14 @@ HttpUpgradeProtocolAccess::forApplicable(const ProtocolView &offer, const Visito seenApplicable = true; // may already be true } if (!seenApplicable && other) // OTHER is applicable if named rules were not - (void)visitor(ProtoOther, other); + (void)visitor(ProtoOther(), other); +} + +inline const SBuf & +HttpUpgradeProtocolAccess::ProtoOther() +{ + static const auto proto = new SBuf("OTHER"); + return *proto; } #endif /* SQUID_SRC_HTTPUPGRADEPROTOCOLACCESS_H */ diff --git a/src/tests/stub_HttpUpgradeProtocolAccess.cc b/src/tests/stub_HttpUpgradeProtocolAccess.cc index 068ce24057..b3648eb360 100644 --- a/src/tests/stub_HttpUpgradeProtocolAccess.cc +++ b/src/tests/stub_HttpUpgradeProtocolAccess.cc @@ -19,7 +19,6 @@ std::ostream &operator <<(std::ostream &os, const ProtocolView &) STUB_RETVAL(os HttpUpgradeProtocolAccess::~HttpUpgradeProtocolAccess() STUB const acl_access *HttpUpgradeProtocolAccess::findGuard(const SBuf &) const STUB_RETVAL(nullptr) void HttpUpgradeProtocolAccess::configureGuard(ConfigParser &) STUB -const SBuf HttpUpgradeProtocolAccess::ProtoOther("STUB-OTHER"); HttpUpgradeProtocolAccess::NamedGuard::~NamedGuard() STUB_NOP HttpUpgradeProtocolAccess::NamedGuard::NamedGuard(const char *, acl_access *): protocol("STUB-UNDEF"), proto(protocol) STUB_NOP