test-inspect: reset locale after gtk_init()
PATCH 1/1 test-inspect: reset locale after gtk_init()
The test-inspect tool uses GTK to visualize symbol nodes. It turns out that gtk_init() implicitly sets the locale to the system locale, and since Sparse uses strtod()/strtold() for parsing floating-point numbers in expressions, parsing becomes locale-dependent.
Since the system's locale may be different from "C", test-inspect may be unable to parse float numbers.
Steps to reproduce:
$ echo "int main(void){3.14;}" > test.c
$ LC_ALL="fr_FR.UTF-8" test-inspect test.c
Output:
test.c:1:16: error: constant 3.14 is not a valid numberFix this by resetting the locale right after gtk_init().
--- test-inspect.c | 2 ++ 1 file changed, 2 insertions(+)
test-inspect.c +2 -0
@@ -6,6 +6,7 @@#include <ctype.h> #include <unistd.h> #include <fcntl.h> +#include <locale.h> #include "lib.h" #include "allocate.h"
@@ -31,6 +32,7 @@ int main(int argc, char **argv)struct symbol_list *view_syms =NULL ;gtk_init (&argc,&argv); +setlocale (LC_ALL ,"C" );expand_symbols (sparse_initialize (argc, argv, &filelist)); FOR_EACH_PTR(filelist, file) {struct symbol_list *syms =sparse (file);
Signature · 1 line
2.11.0
Quoted 5 lines · Davidson Francis
The test-inspect tool uses GTK to visualize symbol nodes. It turns out that
gtk_init()implicitly sets the locale to the system locale, and since Sparse uses strtod()/strtold() for parsing floating-point numbers in expressions, parsing becomes locale-dependent.
We probably shouldn't be using strtod/strtold in the first place because of issues like this, but I think your patch is likely the simplest fix.
It _might_ be a good idea to limit it to LC_NUMERIC instead of LC_ALL, but who knows.. I'm not sure what else might be affected (and I'm not sure how good LC_NUMERIC support is on all platforms)
Linus
Quoted 6 lines · Linus Torvalds
Quoted 5 lines · Davidson Francis
The test-inspect tool uses GTK to visualize symbol nodes. It turns out that
gtk_init()implicitly sets the locale to the system locale, and since Sparse uses strtod()/strtold() for parsing floating-point numbers in expressions, parsing becomes locale-dependent.
Oh yes, indeed :(
Thanks for the patch.
Quoted 3 lines
We probably shouldn't be using strtod/strtold in the first place because of issues like this, but I think your patch is likely the simplest fix.
Yes.
Quoted 3 lines
It _might_ be a good idea to limit it to
LC_NUMERICinstead ofLC_ALL, but who knows.. I'm not sure what else might be affected (and I'm not sure how goodLC_NUMERICsupport is on all platforms)
Well, checking the standard, I see that strtold() first strips whitespaces as defined by isspace() and isspace() itself depends on LC_CTYPE. So, for the moment, I prefer to take Davidson's patch as is this (OTOH, we already depend on isspace() anyway).
-- Luc
Quoted 7 lines · Luc Van Oostenryck
Quoted 5 lines · Linus Torvalds
It _might_ be a good idea to limit it to
LC_NUMERICinstead ofLC_ALL,
but who knows.. I'm not sure what else might be affected (and I'm not
sure how goodLC_NUMERICsupport is on all platforms)
Quoted 6 lines
Well, checking the standard, I see that
strtold()first strips whitespaces as defined byisspace()andisspace()itself depends onLC_CTYPE. So, for the moment, I prefer to take Davidson's patch as is this (OTOH, we already depend onisspace()anyway).-- Luc
I was also in doubt as to what would be the most appropriate option. Anyway, thanks for accepting the patch.
Regards,
Davidson Francis.