]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
NoNewGlobals: HttpUpgradeProtocolAccess::ProtoOther (#1745)
authorFrancesco Chemolli <5175948+kinkie@users.noreply.github.com>
Tue, 19 Mar 2024 01:55:14 +0000 (01:55 +0000)
committerSquid Anubis <squid-anubis@squid-cache.org>
Tue, 19 Mar 2024 07:58:50 +0000 (07:58 +0000)
Detected by Coverity. CID 1554674: Initialization or destruction
ordering is unspecified (GLOBAL_INIT_ORDER).

src/HttpUpgradeProtocolAccess.cc
src/HttpUpgradeProtocolAccess.h
src/tests/stub_HttpUpgradeProtocolAccess.cc

index 6bd099c564f023947cfebab2e60f7b4573e598ef..ff4d572b48dcd1a01d91753e5bf26a1a56ec4dbb 100644 (file)
@@ -17,8 +17,6 @@
 
 #include <algorithm>
 
-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;
     }
index ae8a02ee116c14d05f71e61c4dab13eb1aa8cbff..a310cd86fab7e12977fa863f81290b4ceebecda3 100644 (file)
@@ -82,7 +82,7 @@ private:
     typedef std::deque<NamedGuard> 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 <typename Visitor>
@@ -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 */
index 068ce2405781b94689ca7a816a0648120d5cfa54..b3648eb3603c1c9c47b86b490c0047cc31c5c6b1 100644 (file)
@@ -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