Skip to content

Commit c8d33e2

Browse files
authored
BUG: Fix crashing due to use of std::string as a constant in headers. (#26)
* BUG: Use StringLiteral class to avoid crashes on launch due to unintialized std::string constants * COMP: Add missing #include directive for tbb task_group --------- Signed-off-by: Michael Jackson <mike.jackson@bluequartz.net>
1 parent 742275f commit c8d33e2

14 files changed

+319
-54
lines changed

Source/EbsdLib/Core/EbsdLibConstants.h

Lines changed: 53 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
#include <cstdint>
3939
#include <string>
4040

41+
#include "EbsdLib/Core/StringLiteral.hpp"
42+
43+
4144
/**
4245
* @file EbsdConstants.h
4346
* @brief This file contains many constants that are generic to the EBSD library
@@ -47,7 +50,7 @@ namespace EbsdLib
4750

4851
using Rgb = uint32_t;
4952
inline constexpr Rgb RGB_MASK = 0x00ffffff; // masks RGB values
50-
inline const std::string PathSep("|");
53+
inline constexpr StringLiteral PathSep = "|";
5154
inline constexpr uint8_t Unchecked = 0;
5255
inline constexpr uint8_t PartiallyChecked = 1;
5356
inline constexpr uint8_t Checked = 2;
@@ -64,28 +67,28 @@ enum InfoStringFormat
6467

6568
namespace StringConstants
6669
{
67-
inline const std::string Statistics("Statistics");
68-
inline const std::string StatsData("StatsData");
69-
inline const std::string StatsType("StatsType");
70-
inline const std::string GBCD("GBCD");
70+
inline constexpr StringLiteral Statistics = "Statistics";
71+
inline constexpr StringLiteral StatsData = "StatsData";
72+
inline constexpr StringLiteral StatsType = "StatsType";
73+
inline constexpr StringLiteral GBCD = "GBCD";
7174
} // namespace StringConstants
7275

7376
namespace NumericTypes
7477
{
7578
namespace Names
7679
{
77-
inline const std::string Int8("signed int 8 bit");
78-
inline const std::string UInt8("unsigned int 8 bit");
79-
inline const std::string Int16("signed int 16 bit");
80-
inline const std::string UInt16("unsigned int 16 bit");
81-
inline const std::string Int32("signed int 32 bit");
82-
inline const std::string UInt32("unsigned int 32 bit");
83-
inline const std::string Int64("signed int 64 bit");
84-
inline const std::string UInt64("unsigned int 64 bit");
85-
inline const std::string Float("Float 32 bit");
86-
inline const std::string Double("Double 64 bit");
87-
inline const std::string Bool("Bool");
88-
inline const std::string SizeT("size_t");
80+
inline constexpr StringLiteral Int8 = "signed int 8 bit";
81+
inline constexpr StringLiteral UInt8 = "unsigned int 8 bit";
82+
inline constexpr StringLiteral Int16 = "signed int 16 bit";
83+
inline constexpr StringLiteral UInt16 = "unsigned int 16 bit";
84+
inline constexpr StringLiteral Int32 = "signed int 32 bit";
85+
inline constexpr StringLiteral UInt32 = "unsigned int 32 bit";
86+
inline constexpr StringLiteral Int64 = "signed int 64 bit";
87+
inline constexpr StringLiteral UInt64 = "unsigned int 64 bit";
88+
inline constexpr StringLiteral Float = "Float 32 bit";
89+
inline constexpr StringLiteral Double = "Double 64 bit";
90+
inline constexpr StringLiteral Bool = "Bool";
91+
inline constexpr StringLiteral SizeT = "size_t";
8992
} // namespace Names
9093

9194
enum class Type : int32_t
@@ -105,9 +108,9 @@ enum class Type : int32_t
105108
UnknownNumType
106109
};
107110

108-
inline const std::string SupportedTypeList(NumericTypes::Names::Int8 + ", " + NumericTypes::Names::UInt8 + ", " + NumericTypes::Names::Int16 + ", " + NumericTypes::Names::UInt16 + ", " +
109-
NumericTypes::Names::Int32 + ", " + NumericTypes::Names::UInt32 + ", " + NumericTypes::Names::Int64 + ", " + NumericTypes::Names::UInt64 + ", " +
110-
NumericTypes::Names::Float + ", " + NumericTypes::Names::Double + ", " + NumericTypes::Names::Bool + ", " + NumericTypes::Names::SizeT);
111+
inline std::string SupportedTypeList(NumericTypes::Names::Int8.str() + ", " + NumericTypes::Names::UInt8.str() + ", " + NumericTypes::Names::Int16.str() + ", " + NumericTypes::Names::UInt16.str() + ", " +
112+
NumericTypes::Names::Int32.str() + ", " + NumericTypes::Names::UInt32.str() + ", " + NumericTypes::Names::Int64.str() + ", " + NumericTypes::Names::UInt64.str() + ", " +
113+
NumericTypes::Names::Float.str() + ", " + NumericTypes::Names::Double.str() + ", " + NumericTypes::Names::Bool.str() + ", " + NumericTypes::Names::SizeT.str() );
111114
} // namespace NumericTypes
112115

113116
/** @brief RefFrameZDir defined for the Stacking order of images into a 3D Volume */
@@ -120,35 +123,35 @@ inline constexpr uint32_t UnknownRefFrameZDirection = 2;
120123

121124
namespace H5Ebsd
122125
{
123-
inline const std::string Manufacturer("Manufacturer");
124-
inline const std::string Header("Header");
125-
inline const std::string Phases("Phases");
126-
inline const std::string Phase("Phase");
127-
inline const std::string Data("Data");
128-
inline const std::string Index("Index");
129-
130-
inline const std::string ZStartIndex("ZStartIndex");
131-
inline const std::string ZEndIndex("ZEndIndex");
132-
inline const std::string ZResolution("Z Resolution");
133-
inline const std::string StackingOrder("Stacking Order");
134-
inline const std::string SampleTransformationAngle("SampleTransformationAngle");
135-
inline const std::string SampleTransformationAxis("SampleTransformationAxis");
136-
inline const std::string EulerTransformationAngle("EulerTransformationAngle");
137-
inline const std::string EulerTransformationAxis("EulerTransformationAxis");
126+
inline constexpr StringLiteral Manufacturer = "Manufacturer";
127+
inline constexpr StringLiteral Header = "Header";
128+
inline constexpr StringLiteral Phases = "Phases";
129+
inline constexpr StringLiteral Phase = "Phase";
130+
inline constexpr StringLiteral Data = "Data";
131+
inline constexpr StringLiteral Index = "Index";
132+
133+
inline constexpr StringLiteral ZStartIndex = "ZStartIndex";
134+
inline constexpr StringLiteral ZEndIndex = "ZEndIndex";
135+
inline constexpr StringLiteral ZResolution = "Z Resolution";
136+
inline constexpr StringLiteral StackingOrder = "Stacking Order";
137+
inline constexpr StringLiteral SampleTransformationAngle = "SampleTransformationAngle";
138+
inline constexpr StringLiteral SampleTransformationAxis = "SampleTransformationAxis";
139+
inline constexpr StringLiteral EulerTransformationAngle = "EulerTransformationAngle";
140+
inline constexpr StringLiteral EulerTransformationAxis = "EulerTransformationAxis";
138141

139142
// Each Manufacturer has their own naming scheme for these variables but for
140143
// DREAM.3D we are going to settle on using these names for consistency
141-
inline const std::string XResolution("X Resolution");
142-
inline const std::string YResolution("Y Resolution");
144+
inline constexpr StringLiteral XResolution = "X Resolution";
145+
inline constexpr StringLiteral YResolution = "Y Resolution";
143146

144147
// We store the Maximum number of X and Y Points for the given volume. This
145148
// allows us to store slices that have different XY voxel dimensions.
146-
inline const std::string XPoints("Max X Points");
147-
inline const std::string YPoints("Max Y Points");
149+
inline constexpr StringLiteral XPoints = "Max X Points";
150+
inline constexpr StringLiteral YPoints = "Max Y Points";
148151

149-
inline const std::string FileVersionStr("FileVersion");
152+
inline constexpr StringLiteral FileVersionStr = "FileVersion";
150153
inline constexpr uint32_t FileVersion = 5;
151-
inline const std::string EbsdLibVersionStr("EbsdLibVersion");
154+
inline constexpr StringLiteral EbsdLibVersionStr = "EbsdLibVersion";
152155
} // namespace H5Ebsd
153156

154157
using EnumType = int32_t;
@@ -167,8 +170,8 @@ enum class OEM : EnumType
167170

168171
namespace CellData
169172
{
170-
inline const std::string EulerAngles("EulerAngles");
171-
inline const std::string Phases("Phases");
173+
inline constexpr StringLiteral EulerAngles = "EulerAngles";
174+
inline constexpr StringLiteral Phases = "Phases";
172175
} // namespace CellData
173176

174177
enum EbsdToSampleCoordinateMapping
@@ -181,9 +184,9 @@ enum EbsdToSampleCoordinateMapping
181184

182185
namespace StackingOrder
183186
{
184-
inline const std::string LowToHigh("Low To High");
185-
inline const std::string HighToLow("High To Low");
186-
inline const std::string UnknownStackingOrder("Unknown Stacking Order");
187+
inline constexpr StringLiteral LowToHigh = "Low To High";
188+
inline constexpr StringLiteral HighToLow = "High To Low";
189+
inline constexpr StringLiteral UnknownStackingOrder = "Unknown Stacking Order";
187190

188191
namespace Utils
189192
{
@@ -241,9 +244,9 @@ inline constexpr uint32_t UnknownCrystalStructure = 999; //!< UnknownCrystalStru
241244

242245
namespace BravaisLattice
243246
{
244-
inline const std::string Unknown("Unknown");
245-
inline const std::string Cubic("Cubic");
246-
inline const std::string Hexagonal("Hexagonal");
247+
inline constexpr StringLiteral Unknown = "Unknown";
248+
inline constexpr StringLiteral Cubic = "Cubic";
249+
inline constexpr StringLiteral Hexagonal = "Hexagonal";
247250
} // namespace BravaisLattice
248251

249252
namespace AngleRepresentation
@@ -292,3 +295,4 @@ inline constexpr double BP[6] = {0.0, 1.0, 0.5773502691896260, 0.414213562373095
292295
namespace LPs = LambertParametersType;
293296

294297
} // namespace EbsdLib
298+

Source/EbsdLib/Core/SourceList.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ set(EbsdLib_${DIR_NAME}_HDRS
1212
${EbsdLibProj_SOURCE_DIR}/Source/EbsdLib/${DIR_NAME}/OrientationRepresentation.h
1313
${EbsdLibProj_SOURCE_DIR}/Source/EbsdLib/${DIR_NAME}/OrientationTransformation.hpp
1414
${EbsdLibProj_SOURCE_DIR}/Source/EbsdLib/${DIR_NAME}/Quaternion.hpp
15+
${EbsdLibProj_SOURCE_DIR}/Source/EbsdLib/${DIR_NAME}/StringLiteral.hpp
1516
)
1617

1718
set(EbsdLib_${DIR_NAME}_SRCS

0 commit comments

Comments
 (0)