* [PATCH] Fix strtod handling of multi-byte thousands separator
@ 2007-01-11 16:29 Jakub Jelinek
2007-01-11 17:38 ` Ulrich Drepper
0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2007-01-11 16:29 UTC (permalink / raw)
To: Ulrich Drepper; +Cc: Glibc hackers
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] Fix strtod handling of multi-byte thousands separator
2007-01-11 16:29 [PATCH] Fix strtod handling of multi-byte thousands separator Jakub Jelinek
@ 2007-01-11 17:38 ` Ulrich Drepper
0 siblings, 0 replies; 2+ messages in thread
From: Ulrich Drepper @ 2007-01-11 17:38 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: Glibc hackers
[-- Attachment #1: Type: text/plain, Size: 123 bytes --]
I applied both strtod patches.
--
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 251 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2007-01-11 17:38 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-01-11 16:29 [PATCH] Fix strtod handling of multi-byte thousands separator Jakub Jelinek
2007-01-11 17:38 ` Ulrich Drepper
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).