This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] gethex doesn't cope with multibyte decimalpoints


On Mar 23 15:14, Corinna Vinschen wrote:
> Below is another solution for this problem.  It's sticking to the right
> to left reading order in the main loop, while allowing to specify a
> multibyte decimal point.  The calculation of decpt should be correct now.
> In the orginal code, decpt is pointing to the character succeeding the
> decimal point.  The pointer s is always >= decpt.  The below code also
> sets decpt to the next char succeeding the multibyte decimal point and s
> is still >= decpt.  So the calculation of e is still the same as in the
> original code.
> 
> The main loop now checks for the trailing byte in the decimal point char
> and if it hits that char, it first checks if the strcmp would still be
> within the s0 margin.  If the decimal point has been detected, s1 is set
> back to the leading byte of the decimal point character.  Then the loop
> continues with the next *--s1 which points to the next digit preceeding
> the decimal point.
> 
> I changed strtod and wcstod accordingly to cope correctly with multibyte
> decimal points.  I also removed the USE_LOCALE define in gdtoa-gethex.c
> and strtod.c since it's not used or set anywhere in newlib's configury.
> [...]

Apart from the fact that I accidentally checked this in, it had a nice
little bug:

> Index: libc/stdlib/strtod.c
> ===================================================================
> RCS file: /cvs/src/src/newlib/libc/stdlib/strtod.c,v
> retrieving revision 1.12
> diff -u -p -r1.12 strtod.c
> --- libc/stdlib/strtod.c	27 Nov 2008 20:45:37 -0000	1.12
> +++ libc/stdlib/strtod.c	23 Mar 2009 13:55:03 -0000
> @@ -122,9 +122,7 @@ THIS SOFTWARE.
>  /* #include <fenv.h> */
>  /* #endif */
>  
> -#ifdef USE_LOCALE
>  #include "locale.h"
> -#endif
>  
>  #ifdef IEEE_Arith
>  #ifndef NO_IEEE_Scale
> @@ -307,14 +305,10 @@ _DEFUN (_strtod_r, (ptr, s00, se),
>  		else if (nd < 16)
>  			z = 10*z + c - '0';
>  	nd0 = nd;
> -#ifdef USE_LOCALE
> -	if (c == *localeconv()->decimal_point)
> -#else
> -	if (c == '.')
> -#endif
> +	if (strcmp (s, localeconv()->decimal_point) == 0)

Make that:

        if (strncmp (s, localeconv()->decimal_point,
		     strlen (localeconv()->decimal_point)) == 0)

Sorry,
Corinna

-- 
Corinna Vinschen
Cygwin Project Co-Leader
Red Hat


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]