From dd0e6261337df4384df3bb94ffe691bcd67307be Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Sat, 29 Mar 2025 01:18:37 +0600 Subject: [PATCH] Set LC_NUMERIC to "C" in program startup For whatever fucking reason, glibc's functions dealing with decimal numbers apparently can only accept either commas or dots in strings, but not both. Meanwhile, both Windows and macOS have no apparent issues accepting both. I will never understand why they decided to even consider such behaviour acceptable, especially since those ARE used for parsing decimal numbers in many programs, but I guess it's their own version of Not Invented Here syndrome that they (or anyone else) can't be bothered to deal with. This is not how good C standard libraries are written, at all. --- src/qt/qt_main.cpp | 3 +++ src/utils/ini.c | 17 ++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/qt/qt_main.cpp b/src/qt/qt_main.cpp index 2e0ce33e0..2ef797bd1 100644 --- a/src/qt/qt_main.cpp +++ b/src/qt/qt_main.cpp @@ -94,6 +94,8 @@ extern int qt_nvr_save(void); bool cpu_thread_running = false; } +#include + void qt_set_sequence_auto_mnemonic(bool b); #ifdef Q_OS_WINDOWS @@ -525,6 +527,7 @@ main(int argc, char *argv[]) QApplication app(argc, argv); QLocale::setDefault(QLocale::C); + setlocale(LC_NUMERIC, "C"); #ifdef Q_OS_WINDOWS Q_INIT_RESOURCE(darkstyle); diff --git a/src/utils/ini.c b/src/utils/ini.c index f5dfdef46..e23f83670 100644 --- a/src/utils/ini.c +++ b/src/utils/ini.c @@ -756,8 +756,9 @@ double ini_section_get_double(ini_section_t self, const char *name, double def) { section_t *section = (section_t *) self; - const entry_t *entry; - double value = 0; + entry_t *entry; + double value = 0; + int res = 0; if (section == NULL) return def; @@ -766,7 +767,17 @@ ini_section_get_double(ini_section_t self, const char *name, double def) if (entry == NULL) return def; - sscanf(entry->data, "%lg", &value); + res = sscanf(entry->data, "%lg", &value); + if (res == EOF || res <= 0) { + int i = 0; + for (i = 0; i < strlen(entry->data); i++) { + if (entry->data[i] == ',') { + entry->data[i] = '.'; + entry->wdata[i] = L'.'; + } + } + (void)sscanf(entry->data, "%lg", &value); + } return value; }