scriptstdstring parseFloat bug

Started by
2 comments, last by WitchLord 6 years, 2 months ago

Hi,

I just found this piece of code in the scriptstdstring addon:


	// WinCE doesn't have setlocale. Some quick testing on my current platform
	// still manages to parse the numbers such as "3.14" even if the decimal for the
	// locale is ",".
#if !defined(_WIN32_WCE) && !defined(ANDROID) && !defined(__psp2__)
	// Set the locale to C so that we are guaranteed to parse the float value correctly
	char *orig = setlocale(LC_NUMERIC, 0);
	setlocale(LC_NUMERIC, "C");
#endif

	double res = strtod(val.c_str(), &end);

#if !defined(_WIN32_WCE) && !defined(ANDROID) && !defined(__psp2__)
	// Restore the locale
	setlocale(LC_NUMERIC, orig);
#endif

But, this seems to be invalid code, since the second setlocale call will invalidate the first "orig" pointer, as described on MSDN: https://msdn.microsoft.com/en-us/library/x99tb11d.aspx

Quote

You can copy the string returned by setlocale to restore that part of the program's locale information. Global or thread local storage is used for the string returned by setlocale. Later calls to setlocale overwrite the string, which invalidates string pointers returned by earlier calls.

 

Advertisement

Thanks. You're right. This appears to be a bug. I'll have it fixed.

Regards,
Andreas

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

I've fixed this in revision 2468.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This topic is closed to new replies.

Advertisement