From 6342e52f95e1f7a34a8ec37d47d885d44d42848b Mon Sep 17 00:00:00 2001 From: Daniel Stevens Date: Mon, 3 Mar 2025 17:44:03 -0700 Subject: [PATCH 1/5] Move `XmlBase::entity` to unnamed namespace This field generated a warning with Clang flag `-Wpadded`. Moving it from the header to the source reduces the number of warnings generated. --- NAS2D/Xml/XmlBase.h | 15 --------------- NAS2D/Xml/XmlParser.cpp | 35 +++++++++++++++++++++++------------ 2 files changed, 23 insertions(+), 27 deletions(-) diff --git a/NAS2D/Xml/XmlBase.h b/NAS2D/Xml/XmlBase.h index 9a7e3afcf..2098253ea 100644 --- a/NAS2D/Xml/XmlBase.h +++ b/NAS2D/Xml/XmlBase.h @@ -127,21 +127,6 @@ class XmlBase ParseLocation location{}; private: - struct Entity - { - const char* str; - unsigned int strLength; - char chr; - }; - - enum - { - NUM_ENTITY = 5, - MAX_ENTITY_LENGTH = 6 - - }; - - static Entity entity[NUM_ENTITY]; static bool condenseWhiteSpace; }; diff --git a/NAS2D/Xml/XmlParser.cpp b/NAS2D/Xml/XmlParser.cpp index a6276a9d4..947c01a30 100644 --- a/NAS2D/Xml/XmlParser.cpp +++ b/NAS2D/Xml/XmlParser.cpp @@ -70,6 +70,29 @@ namespace "Error parsing CDATA.", "Error adding XmlDocument to document: XmlDocument can only be at the root.", }; + + struct Entity + { + const char* str; + unsigned int strLength; + char chr; + }; + + enum + { + NUM_ENTITY = 5, + MAX_ENTITY_LENGTH = 6 + + }; + + Entity entity[NUM_ENTITY] = + { + { "&", 5, '&' }, + { "<", 4, '<' }, + { ">", 4, '>' }, + { """, 6, '\"' }, + { "'", 6, '\'' } + }; } @@ -77,18 +100,6 @@ namespace NAS2D { namespace Xml { -// Note that "PutString" hardcodes the same list. This is less flexible -// than it appears. Changing the entries or order will break putstring. -XmlBase::Entity XmlBase::entity[ XmlBase::NUM_ENTITY ] = -{ - { "&", 5, '&' }, - { "<", 4, '<' }, - { ">", 4, '>' }, - { """, 6, '\"' }, - { "'", 6, '\'' } -}; - - int XmlBase::isAlpha(unsigned char anyByte) { if (anyByte < 127) From 728acc478ba011ca2940dd96c6c0477634d7b05d Mon Sep 17 00:00:00 2001 From: Daniel Stevens Date: Mon, 3 Mar 2025 18:06:04 -0700 Subject: [PATCH 2/5] Re-arrange `XmlNode` fields and add explicit padding --- NAS2D/Xml/XmlNode.cpp | 8 ++++---- NAS2D/Xml/XmlNode.h | 8 +++----- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/NAS2D/Xml/XmlNode.cpp b/NAS2D/Xml/XmlNode.cpp index 69bf7feca..0f362ceb3 100644 --- a/NAS2D/Xml/XmlNode.cpp +++ b/NAS2D/Xml/XmlNode.cpp @@ -17,11 +17,11 @@ using namespace NAS2D::Xml; XmlNode::XmlNode() : XmlBase(), _parent(nullptr), - _type(NodeType::XML_UNKNOWN), _firstChild(nullptr), _lastChild(nullptr), _prev(nullptr), - _next(nullptr) + _next(nullptr), + _type(NodeType::XML_UNKNOWN) {} @@ -33,11 +33,11 @@ XmlNode::XmlNode() : XmlNode::XmlNode(NodeType type) : XmlBase(), _parent(nullptr), - _type(type), _firstChild(nullptr), _lastChild(nullptr), _prev(nullptr), - _next(nullptr) + _next(nullptr), + _type(type) {} diff --git a/NAS2D/Xml/XmlNode.h b/NAS2D/Xml/XmlNode.h index 41d5d8569..862e592f2 100644 --- a/NAS2D/Xml/XmlNode.h +++ b/NAS2D/Xml/XmlNode.h @@ -153,15 +153,13 @@ class XmlNode : public XmlBase XmlNode* identify(const char* start); XmlNode* _parent; - NodeType _type; - XmlNode* _firstChild; XmlNode* _lastChild; - - std::string _value{}; - XmlNode* _prev; XmlNode* _next; + std::string _value{}; + NodeType _type; + int _padding{}; private: friend class XmlDocument; From 9b6bee6f11145675303335d0e91088cc99a0289c Mon Sep 17 00:00:00 2001 From: Daniel Stevens Date: Mon, 3 Mar 2025 18:07:22 -0700 Subject: [PATCH 3/5] Re-arrange `XmlDocument` fields and add explicit padding --- NAS2D/Xml/XmlDocument.h | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/NAS2D/Xml/XmlDocument.h b/NAS2D/Xml/XmlDocument.h index a5a356dc1..93bfcb8aa 100644 --- a/NAS2D/Xml/XmlDocument.h +++ b/NAS2D/Xml/XmlDocument.h @@ -59,12 +59,10 @@ class XmlDocument : public XmlNode private: XmlErrorCode _errorId{}; - - bool _error{}; - - std::string _errorDesc{}; - XmlBase::ParseLocation _errorLocation{}; + std::string _errorDesc{}; + bool _error{}; + char padding[7]; }; } // namespace Xml From 35249e6d10370b4a8d1c092fe1356df745e0db79 Mon Sep 17 00:00:00 2001 From: Daniel Stevens Date: Mon, 3 Mar 2025 18:08:02 -0700 Subject: [PATCH 4/5] Add explicit padding to `XmlText` --- NAS2D/Xml/XmlText.h | 1 + 1 file changed, 1 insertion(+) diff --git a/NAS2D/Xml/XmlText.h b/NAS2D/Xml/XmlText.h index 19bf41c9a..b90f4b23a 100644 --- a/NAS2D/Xml/XmlText.h +++ b/NAS2D/Xml/XmlText.h @@ -64,6 +64,7 @@ class XmlText : public XmlNode private: bool cdata{}; // true if this should be input and output as a CDATA style text element + char padding[7]{}; }; } // namespace Xml From bf630ff65af551f38295e5b9febd37fe9f5d05b2 Mon Sep 17 00:00:00 2001 From: Daniel Stevens Date: Mon, 3 Mar 2025 18:46:48 -0700 Subject: [PATCH 5/5] Re-arrange `XmlMemoryBuffer` fields and add explicit padding --- NAS2D/Xml/XmlMemoryBuffer.cpp | 2 +- NAS2D/Xml/XmlMemoryBuffer.h | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/NAS2D/Xml/XmlMemoryBuffer.cpp b/NAS2D/Xml/XmlMemoryBuffer.cpp index 8053de669..d1483232b 100644 --- a/NAS2D/Xml/XmlMemoryBuffer.cpp +++ b/NAS2D/Xml/XmlMemoryBuffer.cpp @@ -37,7 +37,7 @@ inline void line_break(const std::string& linebreak, std::string& buffer) } -XmlMemoryBuffer::XmlMemoryBuffer() : depth(0), _indent("\t"), _lineBreak("\n") +XmlMemoryBuffer::XmlMemoryBuffer() : _indent("\t"), _lineBreak("\n"), depth(0) {} diff --git a/NAS2D/Xml/XmlMemoryBuffer.h b/NAS2D/Xml/XmlMemoryBuffer.h index afb9f9343..456df7ddd 100644 --- a/NAS2D/Xml/XmlMemoryBuffer.h +++ b/NAS2D/Xml/XmlMemoryBuffer.h @@ -53,11 +53,12 @@ class XmlMemoryBuffer : public XmlVisitor const std::string& buffer(); private: - int depth; - std::string _buffer{}; std::string _indent; std::string _lineBreak; + int depth; +protected: + int _padding{}; }; } // namespace Xml