From bbbadebce56b7b891065e05077a225d61ae6fa1a Mon Sep 17 00:00:00 2001 From: Patrick Ohly 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] Change-Id: Ifa6dcd44ce059cf3ec8c99764bd6ea0c677cdd6d Signed-off-by: Patrick Ohly Signed-off-by: Radoslaw Bartosiak --- src/common/types/PolicyKey.cpp | 13 ++++++++++--- src/common/types/PolicyKey.h | 12 ++++++------ 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/common/types/PolicyKey.cpp b/src/common/types/PolicyKey.cpp index ffb1400..d792d45 100644 --- a/src/common/types/PolicyKey.cpp +++ b/src/common/types/PolicyKey.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2014-2015 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -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(void) { + static const std::string value(CYNARA_ADMIN_WILDCARD); + return value; +} + +const std::string &PolicyKeyFeature::anyValue(void) { + 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..d495849 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(void); + const static std::string &anyValue(void); }; class PolicyKey -- 2.7.4