From: Davidson Francis <davidsondfgl@gmail.com>
To: linux-sparse@vger.kernel.org
Cc: Davidson Francis <davidsondfgl@gmail.com>
Subject: [PATCH] test-inspect: reset locale after gtk_init()
Date: Sun, 5 Jul 2020 15:50:13 -0300 [thread overview]
Message-ID: <20200705185013.8578-1-davidsondfgl@gmail.com> (raw)
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
next reply other threads:[~2020-07-05 18:51 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-05 18:50 Davidson Francis [this message]
2020-07-05 19:12 ` [PATCH] test-inspect: reset locale after gtk_init() Linus Torvalds
2020-07-05 20:35 ` Luc Van Oostenryck
2020-07-05 23:28 ` Davidson Francis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200705185013.8578-1-davidsondfgl@gmail.com \
--to=davidsondfgl@gmail.com \
--cc=linux-sparse@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).