From 3372230021a4aeb6e3fcb5f5498efd61d54c74b3 Mon Sep 17 00:00:00 2001 From: Luke Usher Date: Wed, 19 Jun 2024 17:11:58 +0100 Subject: [PATCH] nall: set numeric locale to "C" at startup --- nall/atoi.hpp | 6 +----- nall/main.cpp | 2 ++ nall/string/utility.hpp | 5 ----- 3 files changed, 3 insertions(+), 10 deletions(-) diff --git a/nall/atoi.hpp b/nall/atoi.hpp index bd83881fc3..2ba21f87aa 100644 --- a/nall/atoi.hpp +++ b/nall/atoi.hpp @@ -82,11 +82,7 @@ constexpr inline auto toInteger(const char* s) -> s64 { // inline auto toReal(const char* s) -> f64 { - const char* locale = setlocale(LC_NUMERIC, NULL); - setlocale(LC_NUMERIC, "C"); - auto result = atof(s); - setlocale(LC_NUMERIC, locale); - return result; + return atof(s); } } diff --git a/nall/main.cpp b/nall/main.cpp index c11cf2ad08..2846312268 100644 --- a/nall/main.cpp +++ b/nall/main.cpp @@ -19,6 +19,8 @@ auto main(int argc, char** argv) -> int { _setmode(_fileno(stderr), O_BINARY); #endif + setlocale(LC_NUMERIC, "C"); // Enforce 'standard' locale for numeric formatting + main(Arguments{argc, argv}); #if !defined(PLATFORM_WINDOWS) diff --git a/nall/string/utility.hpp b/nall/string/utility.hpp index 46298f35ce..e7c92ab0dd 100644 --- a/nall/string/utility.hpp +++ b/nall/string/utility.hpp @@ -158,9 +158,6 @@ template inline auto fromHex(char* result, T value) -> char* { //a double to a string ... but attempting to parse a double by //hand, digit-by-digit, results in subtle rounding errors. template inline auto fromReal(char* result, T value) -> u32 { - const char* locale = setlocale(LC_NUMERIC, NULL); - setlocale(LC_NUMERIC, "C"); - char buffer[256]; #ifdef _WIN32 //Windows C-runtime does not support long double via sprintf() @@ -169,8 +166,6 @@ template inline auto fromReal(char* result, T value) -> u32 { snprintf(buffer, sizeof(buffer), "%Lf", (long double)value); #endif - setlocale(LC_NUMERIC, locale); - for(char* p = buffer; *p; p++) { //remove excess 0's in fraction (2.500000 -> 2.5) if(*p == '.') {