dangling pointer in ofXml
Opened this issue · 0 comments
affa0 commented
Version 0.11.1 introduced an issue in ofXml, that leads to random undefined behaviour.
std::locale returns a temporary char*
, this is saved in auto loc
, but the next line ( std::setlocale( LC_NUMERIC, "C" );
) invalidates this internal char*
, so it should not be used anymore from then on.
But in the line 252 it is used again to reset the locale. This leads to random behaviour down the line as the loc
pointer is not valid anymore at that point.
248 float ofXml::getFloatValue() const{
249 auto loc = std::setlocale( LC_NUMERIC, NULL );
250 std::setlocale( LC_NUMERIC, "C" );
251 float f = this->xml.text().as_float();
252 std::setlocale( LC_NUMERIC, loc );
253 return f;
254 }
So this should be changed by saving a deep copy to the char*
, maybe like this:
float ofXml::getFloatValue() const{
std::string loc = std::setlocale( LC_NUMERIC, NULL );
std::setlocale( LC_NUMERIC, "C" );
float f = this->xml.text().as_float();
std::setlocale( LC_NUMERIC, loc.c_str() );
return f;
}
The same change is need in ofXml::Attribute::getFloatValue
, ofXml::Attribute::getFloatValue
and ofXml::Attribute::getFloatValue
as well.