mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
XmlElement: Avoid potential undefined-init-order issues with juce_xmltextContentAttributeName
This fixes potential crashes when this static object is accessed from
the constructors of other objects with static storage duration.
A concrete example of this could be seen when running the following on
Linux:
static inline const Typeface::Ptr face =
Typeface::createSystemTypefaceFor (...);
Here, 'face' is a static data member of some class. Creating a system
typeface on Linux will parse an XML document of system typefaces,
eventually accessing juce_xmltextContentAttributeName.
This commit is contained in:
parent
9844687735
commit
1023f62338
1 changed files with 8 additions and 4 deletions
|
|
@ -918,7 +918,11 @@ bool XmlElement::isTextElement() const noexcept
|
|||
return tagName.isEmpty();
|
||||
}
|
||||
|
||||
static const String juce_xmltextContentAttributeName ("text");
|
||||
static const String& getJuceXmlTextContentAttributeName()
|
||||
{
|
||||
static String result { "text" };
|
||||
return result;
|
||||
}
|
||||
|
||||
const String& XmlElement::getText() const noexcept
|
||||
{
|
||||
|
|
@ -926,13 +930,13 @@ const String& XmlElement::getText() const noexcept
|
|||
// isn't actually a text element.. If this contains text sub-nodes, you
|
||||
// probably want to use getAllSubText instead.
|
||||
|
||||
return getStringAttribute (juce_xmltextContentAttributeName);
|
||||
return getStringAttribute (getJuceXmlTextContentAttributeName());
|
||||
}
|
||||
|
||||
void XmlElement::setText (const String& newText)
|
||||
{
|
||||
if (isTextElement())
|
||||
setAttribute (juce_xmltextContentAttributeName, newText);
|
||||
setAttribute (getJuceXmlTextContentAttributeName(), newText);
|
||||
else
|
||||
jassertfalse; // you can only change the text in a text element, not a normal one.
|
||||
}
|
||||
|
|
@ -964,7 +968,7 @@ String XmlElement::getChildElementAllSubText (StringRef childTagName, const Stri
|
|||
XmlElement* XmlElement::createTextElement (const String& text)
|
||||
{
|
||||
auto e = new XmlElement ((int) 0);
|
||||
e->setAttribute (juce_xmltextContentAttributeName, text);
|
||||
e->setAttribute (getJuceXmlTextContentAttributeName(), text);
|
||||
return e;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue