From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18298 invoked by alias); 11 Jan 2007 16:29:07 -0000 Received: (qmail 18282 invoked by uid 22791); 11 Jan 2007 16:29:06 -0000 X-Spam-Check-By: sourceware.org Received: from sunsite.ms.mff.cuni.cz (HELO sunsite.mff.cuni.cz) (195.113.15.26) by sourceware.org (qpsmtpd/0.31) with ESMTP; Thu, 11 Jan 2007 16:28:59 +0000 Received: from sunsite.mff.cuni.cz (localhost.localdomain [127.0.0.1]) by sunsite.mff.cuni.cz (8.13.8/8.13.8) with ESMTP id l0BGVnpY029829; Thu, 11 Jan 2007 17:31:49 +0100 Received: (from jakub@localhost) by sunsite.mff.cuni.cz (8.13.8/8.13.8/Submit) id l0BGVnt7029828; Thu, 11 Jan 2007 17:31:49 +0100 Date: Thu, 11 Jan 2007 16:29:00 -0000 From: Jakub Jelinek To: Ulrich Drepper Cc: Glibc hackers Subject: [PATCH] Fix strtod handling of multi-byte thousands separator Message-ID: <20070111163149.GC3819@sunsite.mff.cuni.cz> Reply-To: Jakub Jelinek Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.2.2i Mailing-List: contact libc-hacker-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-hacker-owner@sourceware.org X-SW-Source: 2007-01/txt/msg00005.txt.bz2 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 * 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 +#include +#include +#include + +#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