This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit 6b210ed0dfe6d5eebf547ee5362acb1930a4596d
Author: Damian Meden <[email protected]>
AuthorDate: Mon Mar 3 09:45:32 2025 +0100

    Coverity: Avoid order initalization issue 2. (#12037)
    
    Convert from static member to static singleton function.
---
 code/include/swoc/bwf_base.h | 24 +++++++++++++++---------
 code/src/bw_format.cc        |  2 --
 2 files changed, 15 insertions(+), 11 deletions(-)

diff --git a/code/include/swoc/bwf_base.h b/code/include/swoc/bwf_base.h
index e76ccc7..0b21ba2 100644
--- a/code/include/swoc/bwf_base.h
+++ b/code/include/swoc/bwf_base.h
@@ -108,7 +108,7 @@ protected:
   bool is_sign(char c);
 
   /// Handrolled initialization the character syntactic property data.
-  static const struct Property {
+  struct Property {
     Property(); ///< Default constructor, creates initialized flag set.
     /// Flag storage, indexed by character value.
     uint8_t _data[0x100]{};
@@ -118,7 +118,13 @@ protected:
     static constexpr uint8_t UPPER_TYPE_CHAR   = 0x20; ///< Upper case flag.
     static constexpr uint8_t NUMERIC_TYPE_CHAR = 0x40; ///< Numeric output.
     static constexpr uint8_t SIGN_CHAR         = 0x80; ///< Is sign character.
-  } _prop;                                             ///< Character property 
map.
+  };
+  static const Property &
+  Get_Prop()
+  {
+    static const Property prop;
+    return prop;
+  } ///< Character property map.
 };
 
 /** Format string support.
@@ -474,37 +480,37 @@ extern ExternalNames& Global_Names();
 
 inline Spec::Align
 Spec::align_of(char c) {
-  return static_cast<Align>(_prop._data[static_cast<unsigned>(c)] & 
Property::ALIGN_MASK);
+  return static_cast<Align>(Get_Prop()._data[static_cast<unsigned>(c)] & 
Property::ALIGN_MASK);
 }
 
 inline bool
 Spec::is_sign(char c) {
-  return _prop._data[static_cast<unsigned>(c)] & Property::SIGN_CHAR;
+  return Get_Prop()._data[static_cast<unsigned>(c)] & Property::SIGN_CHAR;
 }
 
 inline bool
 Spec::is_type(char c) {
-  return _prop._data[static_cast<unsigned>(c)] & Property::TYPE_CHAR;
+  return Get_Prop()._data[static_cast<unsigned>(c)] & Property::TYPE_CHAR;
 }
 
 inline bool
 Spec::is_upper_case_type(char c) {
-  return _prop._data[static_cast<unsigned>(c)] & Property::UPPER_TYPE_CHAR;
+  return Get_Prop()._data[static_cast<unsigned>(c)] & 
Property::UPPER_TYPE_CHAR;
 }
 
 inline bool
 Spec::is_numeric_type(char c) {
-  return _prop._data[static_cast<unsigned>(c)] & Property::NUMERIC_TYPE_CHAR;
+  return Get_Prop()._data[static_cast<unsigned>(c)] & 
Property::NUMERIC_TYPE_CHAR;
 }
 
 inline bool
 Spec::has_numeric_type() const {
-  return _prop._data[static_cast<unsigned>(_type)] & 
Property::NUMERIC_TYPE_CHAR;
+  return Get_Prop()._data[static_cast<unsigned>(_type)] & 
Property::NUMERIC_TYPE_CHAR;
 }
 
 inline bool
 Spec::has_upper_case_type() const {
-  return _prop._data[static_cast<unsigned>(_type)] & Property::UPPER_TYPE_CHAR;
+  return Get_Prop()._data[static_cast<unsigned>(_type)] & 
Property::UPPER_TYPE_CHAR;
 }
 
 inline bool
diff --git a/code/src/bw_format.cc b/code/src/bw_format.cc
index a5ccbb7..5b87fc9 100644
--- a/code/src/bw_format.cc
+++ b/code/src/bw_format.cc
@@ -37,8 +37,6 @@ ExternalNames& Global_Names() {
 
 const Spec Spec::DEFAULT;
 
-const Spec::Property Spec::_prop;
-
 #pragma GCC diagnostic ignored "-Wchar-subscripts"
 
 Spec::Property::Property() {

Reply via email to