linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] test-inspect: reset locale after gtk_init()
@ 2020-07-05 18:50 Davidson Francis
  2020-07-05 19:12 ` Linus Torvalds
  0 siblings, 1 reply; 4+ messages in thread
From: Davidson Francis @ 2020-07-05 18:50 UTC (permalink / raw)
  To: linux-sparse; +Cc: 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.

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 number

Fix this by resetting the locale right after gtk_init().

Signed-off-by: Davidson Francis <davidsondfgl@gmail.com>
---
 test-inspect.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/test-inspect.c b/test-inspect.c
index 63754cb3..a59cd902 100644
--- a/test-inspect.c
+++ b/test-inspect.c
@@ -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);
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-07-05 23:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-05 18:50 [PATCH] test-inspect: reset locale after gtk_init() Davidson Francis
2020-07-05 19:12 ` Linus Torvalds
2020-07-05 20:35   ` Luc Van Oostenryck
2020-07-05 23:28     ` Davidson Francis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).