The combination of malloc_count and CLI11 breaks with some locales.
Reproducing the error (linux):
In this example I'm using the locale de_DE.UTF-8, make sure it is available:
sudo locale-gen de_DE
sudo locale-gen de_DE.UTF-8
Then the following command produces the error:
LC_ALL=de_DE.UTF-8 ./grlbwt-cli
Output:
terminate called after throwing an instance of 'CLI::ValidationError'
what(): --hbuff: Value 0.15 not in range 0,000000 to 1,000000
[2] 33006 IOT instruction (core dumped) ./grlbwt-cli
Why this happens:external/malloc_count-master/malloc_count.c invokes the following command in init() (line 331):
setlocale(LC_NUMERIC, ""); /* for better readable numbers */
This causes std::to_string and std::stold to use the user's locale (de_DE.UTF-8) instead of the C locale that std::ostream uses. E.g. the simple program
prints 0.15 0,150000 with LC_ALL=de_DE.UTF-8. With LC_ALL=de_DE.UTF-8, std::stold can't parse 0.15 properly (it expects a comma instead of a period).
(CLI11 then says the value 0.15 isn't in the range 0 to 1, but it actually can't parse it.)
Proposed fix:
Either remove the setlocale(LC_NUMERIC, ""); from the included malloc_count.c or "reset" the locale in main.cpp (by calling setlocale(LC_NUMERIC, "C");).
Thanks for the feedback. I just had the same issue with CL11 and another program, and I didn’t understand why. I will try the fix and will get back to you.
The combination of
malloc_count
andCLI11
breaks with some locales.Reproducing the error (linux): In this example I'm using the locale
de_DE.UTF-8
, make sure it is available:Then the following command produces the error:
LC_ALL=de_DE.UTF-8 ./grlbwt-cli
Output:Why this happens:
external/malloc_count-master/malloc_count.c
invokes the following command ininit()
(line 331):setlocale(LC_NUMERIC, ""); /* for better readable numbers */
This causesstd::to_string
andstd::stold
to use the user's locale (de_DE.UTF-8
) instead of theC
locale thatstd::ostream
uses. E.g. the simple programprints
0.15 0,150000
withLC_ALL=de_DE.UTF-8
. WithLC_ALL=de_DE.UTF-8
,std::stold
can't parse0.15
properly (it expects a comma instead of a period).(CLI11 then says the value 0.15 isn't in the range 0 to 1, but it actually can't parse it.)
Proposed fix: Either remove the
setlocale(LC_NUMERIC, "");
from the includedmalloc_count.c
or "reset" the locale inmain.cpp
(by callingsetlocale(LC_NUMERIC, "C");
).