Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dangling pointer in ofXml #7937

Open
affa0 opened this issue May 8, 2024 · 0 comments
Open

dangling pointer in ofXml #7937

affa0 opened this issue May 8, 2024 · 0 comments

Comments

@affa0
Copy link

affa0 commented May 8, 2024

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.

This issue was introduced in 6678 that tried to fix 6111

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant