From fbbdf70401be1be01f6b2df6bd995855be6754d9 Mon Sep 17 00:00:00 2001 From: Saran Tunyasuvunakool Date: Mon, 22 May 2023 05:33:47 -0700 Subject: [PATCH] Make `XMLWriterLocaleTest` hold a copy of the old locale string. The rationale is the same as in 0d0a41d54924e641a7a6e79303abcad20e293034. XMLWriterLocaleTest still sporadically fails with a stack buffer overflow error when built with MSVC 2019 prior to this change. PiperOrigin-RevId: 534035241 Change-Id: I1c50457e386724021b8d97ab1fb9cc2ece795292 --- test/xml/xml_native_writer_test.cc | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/test/xml/xml_native_writer_test.cc b/test/xml/xml_native_writer_test.cc index 1527b201..a5914b62 100644 --- a/test/xml/xml_native_writer_test.cc +++ b/test/xml/xml_native_writer_test.cc @@ -913,17 +913,22 @@ TEST_F(XMLWriterTest, SetPrecision) { } class XMLWriterLocaleTest : public MujocoTest { + public: + XMLWriterLocaleTest() : old_locale_(std::setlocale(LC_ALL, nullptr)) {} + protected: - char* old_locale; void SetUp() override { - this->old_locale = std::setlocale(LC_ALL, nullptr); if (!std::setlocale(LC_ALL, "de_DE.UTF-8")) { GTEST_SKIP() << "This system doesn't support the de_DE.UTF-8 locale"; } } + void TearDown() override { - std::setlocale(LC_ALL, old_locale); + std::setlocale(LC_ALL, old_locale_.c_str()); } + + private: + std::string old_locale_; }; TEST_F(XMLWriterLocaleTest, IgnoresLocale) {