diff mbox

[iputils,6/6] ping: fix -i number parsing in locales

Message ID 1464752905-10347-6-git-send-email-vapier@gentoo.org
State Not Applicable, archived
Delegated to: David Miller
Headers show

Commit Message

Mike Frysinger June 1, 2016, 3:48 a.m. UTC
Always use #.# format for the -i flag even when the current locale uses
a different separator.  Locale de_DE which uses #,# normally.

Simple testcase:
$ make USE_IDN=1
$ LANG=de_DE.UTF8 ./ping -i 0.5 localhost

Reported-by: Sergey Fionov <fionov@gmail.com>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
 ping_common.c | 8 ++++++++
 1 file changed, 8 insertions(+)

Comments

Hideaki Yoshifuji June 2, 2016, 2:08 a.m. UTC | #1
Mike Frysinger wrote:
> Always use #.# format for the -i flag even when the current locale uses
> a different separator.  Locale de_DE which uses #,# normally.
> 
> Simple testcase:
> $ make USE_IDN=1
> $ LANG=de_DE.UTF8 ./ping -i 0.5 localhost
> 
> Reported-by: Sergey Fionov <fionov@gmail.com>
> Signed-off-by: Mike Frysinger <vapier@gentoo.org>
> ---
>  ping_common.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/ping_common.c b/ping_common.c
> index 62f53a6..0a37e09 100644
> --- a/ping_common.c
> +++ b/ping_common.c
> @@ -269,9 +269,17 @@ void common_options(int ch)
>  		double dbl;
>  		char *ep;
>  
> +#ifdef USE_IDN
> +		setlocale(LC_ALL, "C");
> +#endif
> +
>  		errno = 0;
>  		dbl = strtod(optarg, &ep);
>  
> +#ifdef USE_IDN
> +		setlocale(LC_ALL, "");
> +#endif
> +
>  		if (errno || *ep != '\0' ||
>  		    !finite(dbl) || dbl < 0.0 || dbl >= (double)INT_MAX / 1000 - 1.0) {
>  			fprintf(stderr, "ping: bad timing interval\n");
> 

Please make it accept both.
diff mbox

Patch

diff --git a/ping_common.c b/ping_common.c
index 62f53a6..0a37e09 100644
--- a/ping_common.c
+++ b/ping_common.c
@@ -269,9 +269,17 @@  void common_options(int ch)
 		double dbl;
 		char *ep;
 
+#ifdef USE_IDN
+		setlocale(LC_ALL, "C");
+#endif
+
 		errno = 0;
 		dbl = strtod(optarg, &ep);
 
+#ifdef USE_IDN
+		setlocale(LC_ALL, "");
+#endif
+
 		if (errno || *ep != '\0' ||
 		    !finite(dbl) || dbl < 0.0 || dbl >= (double)INT_MAX / 1000 - 1.0) {
 			fprintf(stderr, "ping: bad timing interval\n");