From: Jakub Jelinek <jakub@redhat.com>
To: Ulrich Drepper <drepper@redhat.com>
Cc: Glibc hackers <libc-hacker@sources.redhat.com>
Subject: [PATCH] Fix strtod handling of multi-byte thousands separator
Date: Thu, 11 Jan 2007 16:29:00 -0000 [thread overview]
Message-ID: <20070111163149.GC3819@sunsite.mff.cuni.cz> (raw)
Hi!
While looking at BZ#3855 I noticed that non-wide thousands separators can't
work properly if they are longer than one byte (as shown in the attached
testcase). Fixed thusly:
2007-01-11 Jakub Jelinek <jakub@redhat.com>
* stdlib/strtod_l.c (____STRTOF_INTERNAL): Fix handling of multi-byte
thousands separators.
* stdlib/Makefile: Add rules to build and run tst-strtod4.
* stdlib/tst-strtod4.c: New test.
--- libc/stdlib/strtod_l.c.jj 2007-01-11 17:10:27.000000000 +0100
+++ libc/stdlib/strtod_l.c 2007-01-11 17:10:16.000000000 +0100
@@ -651,10 +651,11 @@ ____STRTOF_INTERNAL (nptr, endptr, group
if (c != '0')
{
for (cnt = 0; thousands[cnt] != '\0'; ++cnt)
- if (c != thousands[cnt])
+ if (thousands[cnt] != cp[cnt])
break;
if (thousands[cnt] != '\0')
break;
+ cp += cnt - 1;
}
c = *++cp;
}
@@ -725,6 +726,7 @@ ____STRTOF_INTERNAL (nptr, endptr, group
break;
if (thousands[cnt] != '\0')
break;
+ cp += cnt - 1;
}
#endif
}
--- libc/stdlib/Makefile.jj 2007-01-10 17:04:12.000000000 +0100
+++ libc/stdlib/Makefile 2007-01-11 17:11:01.000000000 +0100
@@ -68,7 +68,7 @@ tests := tst-strtol tst-strtod testmb t
tst-limits tst-rand48 bug-strtod tst-setcontext \
test-a64l tst-qsort tst-system testmb2 bug-strtod2 \
tst-atof1 tst-atof2 tst-strtod2 tst-strtod3 tst-rand48-2 \
- tst-makecontext
+ tst-makecontext tst-strtod4
include ../Makeconfig
@@ -114,6 +114,7 @@ test-canon-ARGS = --test-dir=${common-ob
tst-strtod-ENV = LOCPATH=$(common-objpfx)localedata
tst-strtod3-ENV = LOCPATH=$(common-objpfx)localedata
+tst-strtod4-ENV = LOCPATH=$(common-objpfx)localedata
testmb2-ENV = LOCPATH=$(common-objpfx)localedata
# Run a test on the header files we use.
--- libc/stdlib/tst-strtod4.c.jj 2007-01-11 16:52:17.000000000 +0100
+++ libc/stdlib/tst-strtod4.c 2007-01-11 17:01:26.000000000 +0100
@@ -0,0 +1,56 @@
+#include <locale.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define NBSP "\xc2\xa0"
+
+static const struct
+{
+ const char *in;
+ const char *out;
+ double expected;
+} tests[] =
+ {
+ { "000"NBSP"000"NBSP"000", "", 0.0 },
+ { "1"NBSP"000"NBSP"000,5x", "x", 1000000.5 }
+ };
+#define NTESTS (sizeof (tests) / sizeof (tests[0]))
+
+
+static int
+do_test (void)
+{
+ if (setlocale (LC_ALL, "cs_CZ.UTF-8") == NULL)
+ {
+ puts ("could not set locale");
+ return 1;
+ }
+
+ int status = 0;
+
+ for (int i = 0; i < NTESTS; ++i)
+ {
+ char *ep;
+ double r = __strtod_internal (tests[i].in, &ep, 1);
+
+ if (strcmp (ep, tests[i].out) != 0)
+ {
+ printf ("%d: got rest string \"%s\", expected \"%s\"\n",
+ i, ep, tests[i].out);
+ status = 1;
+ }
+
+ if (r != tests[i].expected)
+ {
+ printf ("%d: got wrong results %g, expected %g\n",
+ i, r, tests[i].expected);
+ status = 1;
+ }
+ }
+
+ return status;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
Jakub
next reply other threads:[~2007-01-11 16:29 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-01-11 16:29 Jakub Jelinek [this message]
2007-01-11 17:38 ` Ulrich Drepper
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=20070111163149.GC3819@sunsite.mff.cuni.cz \
--to=jakub@redhat.com \
--cc=drepper@redhat.com \
--cc=libc-hacker@sources.redhat.com \
/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 read-only IMAP folder(s) and NNTP newsgroup(s).