From 4cd8acab5a05500107ae508ed28741239d710f81 Mon Sep 17 00:00:00 2001
From: Patrick Ohly <patrick.ohly@intel.com>
Date: Fri, 29 May 2015 12:41:34 +0200
Subject: [PATCH] PolicyKeyFeature: avoid complex global constants

PolicyKeyFeature is used by other global instances in cynara-test
and cannot assume that the initialization of its own static constants
happens first, unless it enforces initialization by embedding
these constants in method calls.

Upstream-status: Submitted [https://github.com/Samsung/cynara/issues/9]

Signed-off-by: Patrick Ohly <patrick.ohly@intel.com>
---
 src/common/types/PolicyKey.cpp | 11 +++++++++--
 src/common/types/PolicyKey.h   | 12 ++++++------
 2 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/src/common/types/PolicyKey.cpp b/src/common/types/PolicyKey.cpp
index ffb1400..d5631c2 100644
--- a/src/common/types/PolicyKey.cpp
+++ b/src/common/types/PolicyKey.cpp
@@ -29,8 +29,15 @@
 
 namespace Cynara {
 
-const std::string PolicyKeyFeature::m_wildcardValue = CYNARA_ADMIN_WILDCARD;
-const std::string PolicyKeyFeature::m_anyValue = CYNARA_ADMIN_ANY;
+const std::string &PolicyKeyFeature::wildcardValue() {
+    static const std::string value(CYNARA_ADMIN_WILDCARD);
+    return value;
+}
+
+const std::string &PolicyKeyFeature::anyValue() {
+    static const std::string value(CYNARA_ADMIN_ANY);
+    return value;
+}
 
 const std::string &PolicyKeyFeature::toString(void) const {
     return value();
diff --git a/src/common/types/PolicyKey.h b/src/common/types/PolicyKey.h
index 4fed189..d5253c6 100644
--- a/src/common/types/PolicyKey.h
+++ b/src/common/types/PolicyKey.h
@@ -49,11 +49,11 @@ public:
     }
 
     static PolicyKeyFeature createWildcard(void) {
-        return PolicyKeyFeature(m_wildcardValue);
+        return PolicyKeyFeature(wildcardValue());
     }
 
     static PolicyKeyFeature createAny(void) {
-        return PolicyKeyFeature(m_anyValue);
+        return PolicyKeyFeature(anyValue());
     }
 
     // TODO: Different features (client, user, privilege)
@@ -86,8 +86,8 @@ public:
 
 protected:
     explicit PolicyKeyFeature(const ValueType &value) : m_value(value),
-        m_isWildcard(value == PolicyKeyFeature::m_wildcardValue),
-        m_isAny(value == PolicyKeyFeature::m_anyValue) {}
+        m_isWildcard(value == wildcardValue()),
+        m_isAny(value == anyValue()) {}
 
     static bool anyAny(const PolicyKeyFeature &pkf1, const PolicyKeyFeature &pkf2) {
         return pkf1.isAny() || pkf2.isAny();
@@ -106,8 +106,8 @@ private:
     bool m_isWildcard;
     bool m_isAny;
 
-    const static std::string m_wildcardValue;
-    const static std::string m_anyValue;
+    const static std::string &wildcardValue();
+    const static std::string &anyValue();
 };
 
 class PolicyKey
-- 
2.1.4

