Calls like
const char* previousCLocale = setlocale(LC_NUMERIC, nullptr); setlocale(LC_NUMERIC, "C");
are invalid because previousCLocale variable becomes invalid after the second setlocale() call.
https://msdn.microsoft.com/ru-ru/library/x99tb11d.aspx:
"Later calls to setlocale overwrite the string, which invalidates string pointers returned by earlier calls."
This may lead to random crashes.
It's possible to reproduce such crash if run debug version of program under Application Verifier with Basics.Heaps option enabled.