Skip to content

Commit 00d6e4f

Browse files
committed
[HTML] Ensure safe global locale fallback setup
1 parent 2c64c40 commit 00d6e4f

1 file changed

Lines changed: 24 additions & 10 deletions

File tree

engine/report/report_html_sim.cpp

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,20 +1164,34 @@ void print_profilesets( std::ostream& out, const profileset::profilesets_t& prof
11641164
out << "</div>";
11651165
}
11661166

1167-
/* Main function building the html document and calling subfunctions
1168-
*/
1169-
void print_html_( report::sc_html_stream& os, sim_t& sim )
1170-
{
1167+
void set_global_locale( ) {
11711168
// Set global locale to en-US for consistent number formatting
1172-
try
1169+
for (const auto& name :
11731170
{
1174-
std::locale::global( std::locale( "en_US.UTF-8" ) );
1175-
}
1176-
catch ( const std::runtime_error& )
1171+
"en_US.UTF-8",
1172+
"en_US.utf8",
1173+
"English_United States.65001",
1174+
"en_US",
1175+
"en-US",
1176+
"English_United States.1252",
1177+
"C"
1178+
})
11771179
{
1178-
// backup spelling for CI
1179-
std::locale::global( std::locale( "en_US.utf8" ) );
1180+
try {
1181+
std::locale::global(std::locale(name));
1182+
return;
1183+
} catch (const std::runtime_error&)
1184+
{ }
11801185
}
1186+
std::locale::global(std::locale::classic());
1187+
}
1188+
1189+
/* Main function building the html document and calling subfunctions
1190+
*/
1191+
void print_html_( report::sc_html_stream& os, sim_t& sim )
1192+
{
1193+
// Set global locale formatting
1194+
set_global_locale();
11811195

11821196
// Set floating point formatting
11831197
os.precision( sim.report_precision );

0 commit comments

Comments
 (0)