Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 27 Jan 2002 16:16:26 -0700
From:      Chad David <davidc@acns.ab.ca>
To:        "Andrey A. Chernov" <ache@nagual.pp.ru>
Cc:        "Brian F. Feldman" <green@FreeBSD.ORG>, Bruce Evans <bde@zeta.org.au>, arch@FreeBSD.ORG
Subject:   Re: strtod()
Message-ID:  <20020127161626.A62332@colnta.acns.ab.ca>
In-Reply-To: <20020127224529.GA20003@nagual.pp.ru>; from ache@nagual.pp.ru on Mon, Jan 28, 2002 at 01:45:30AM %2B0300
References:  <20020126162924.A7726@colnta.acns.ab.ca> <200201270453.g0R4rwi92912@green.bikeshed.org> <20020127070421.GA13415@nagual.pp.ru> <20020127003719.A38420@colnta.acns.ab.ca> <20020127083529.GA13957@nagual.pp.ru> <20020127024626.B40668@colnta.acns.ab.ca> <20020127105258.GA14836@nagual.pp.ru> <20020127130625.A42735@colnta.acns.ab.ca> <20020127224529.GA20003@nagual.pp.ru>

next in thread | previous in thread | raw e-mail | index | archive | help

--8t9RHnE3ZwKMSgU+
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

On Mon, Jan 28, 2002 at 01:45:30AM +0300, Andrey A. Chernov wrote:
> On Sun, Jan 27, 2002 at 13:06:25 -0700, Chad David wrote:
> 
> > $4 = {int_curr_symbol = 0x80549ac "", currency_symbol = 0x80549ac "", 
> >   mon_decimal_point = 0x80549ac "", mon_thousands_sep = 0x80549ac "", 
> >   mon_grouping = 0x80549ad "\177", positive_sign = 0x80549ac "", 
> >   negative_sign = 0x80549ac "", int_frac_digits = 0x80549ad "\177", 
> >   frac_digits = 0x80549ad "\177", p_cs_precedes = 0x80549ad "\177", 
> >   p_sep_by_space = 0x80549ad "\177", n_cs_precedes = 0x80549ad "\177", 
> >   n_sep_by_space = 0x80549ad "\177", p_sign_posn = 0x80549ad "\177", 
> >   n_sign_posn = 0x80549ad "\177"}
> > 
> 
> It looks right. cnv() must be never called on that, it already converted.  

I don't understand what you mean.

> From where failing cnv() call occurse, on which field? Post your minimal
> test, at least.
> 

I've attached the simple program I'm using to test, as well as the gdb
session that should explain what I am doing.

-- 
Chad David        davidc@acns.ab.ca
www.FreeBSD.org   davidc@freebsd.org
ACNS Inc.         Calgary, Alberta Canada
Fourthly, The constant breeders, beside the gain of eight shillings
sterling per annum by the sale of their children, will be rid of the
charge of maintaining them after the first year. - Johnathan Swift

--8t9RHnE3ZwKMSgU+
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="strtod.c"

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <limits.h>

int
main(int argc, char **argv) {
double	d;
char	*c;
int	i;

	if (argc != 2) {
		fprintf(stderr, "Usage: %s [double]\n", argv[0]);
		exit(1);
	}

	for (i = 0; i < 2 ; i++) {
		errno = 0;
		d = strtod(argv[1], &c);

		if (d == 0.0 && errno == EINVAL)
			printf("strtod() failed 1 [%d]\n", i);

		if (d == 0.0 && c == argv[1])
			printf("strtod() failed 2 [%d]\n", i);

		printf("strtod() returned %f [%d]\n", d, i);
	}
	exit(0);
}

--8t9RHnE3ZwKMSgU+
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=gdb1

colnta->gdb strtod                                          /usr/home/davidc/tmp/strtod
GNU gdb 4.18
Copyright 1998 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-unknown-freebsd"...
(gdb) b strtod
Breakpoint 1 at 0x804c484: file /mnt1/devel/work/dev/bsd/FreeBSD/src/lib/libc/../libc/stdlib/strtod.c, line 1201.
(gdb) run 0.0
Starting program: /mnt1/home/davidc/tmp/strtod/strtod 0.0

Breakpoint 1, strtod (s00=0xbfbff82c "0.0", se=0xbfbff6ac)
    at /mnt1/devel/work/dev/bsd/FreeBSD/src/lib/libc/../libc/stdlib/strtod.c:1201
1201            char decimal_point = localeconv()->decimal_point[0];
(gdb) s
localeconv ()
    at /mnt1/devel/work/dev/bsd/FreeBSD/src/lib/libc/../libc/locale/localeconv.c:77
77          if (__mlocale_changed) {
(gdb) s
84              mptr = __get_current_monetary_locale();
(gdb) s
__get_current_monetary_locale ()
    at /mnt1/devel/work/dev/bsd/FreeBSD/src/lib/libc/../libc/locale/lmonetary.c:81
81              return (_monetary_using_locale
(gdb) s
localeconv ()
    at /mnt1/devel/work/dev/bsd/FreeBSD/src/lib/libc/../libc/locale/localeconv.c:85
85              M_ASSIGN_STR(int_curr_symbol);
(gdb) p mptr
$1 = (struct lc_monetary_T *) 0x8052a20
(gdb) p *mptr
$2 = {int_curr_symbol = 0x8054a0c "", currency_symbol = 0x8054a0c "", 
  mon_decimal_point = 0x8054a0c "", mon_thousands_sep = 0x8054a0c "", 
  mon_grouping = 0x8054a0d "\177", positive_sign = 0x8054a0c "", 
  negative_sign = 0x8054a0c "", int_frac_digits = 0x8054a0d "\177", 
  frac_digits = 0x8054a0d "\177", p_cs_precedes = 0x8054a0d "\177", 
  p_sep_by_space = 0x8054a0d "\177", n_cs_precedes = 0x8054a0d "\177", 
  n_sep_by_space = 0x8054a0d "\177", p_sign_posn = 0x8054a0d "\177", 
  n_sign_posn = 0x8054a0d "\177"}
(gdb) s
86              M_ASSIGN_STR(currency_symbol);
(gdb) s
87              M_ASSIGN_STR(mon_decimal_point);
(gdb) s
88              M_ASSIGN_STR(mon_thousands_sep);
(gdb) s
89              M_ASSIGN_STR(mon_grouping);
(gdb) s
90              M_ASSIGN_STR(positive_sign);
(gdb) s
91              M_ASSIGN_STR(negative_sign);
(gdb) s
92              M_ASSIGN_CHAR(int_frac_digits);
(gdb) s
cnv (str=0x8054a0d "\177")
    at /mnt1/devel/work/dev/bsd/FreeBSD/src/lib/libc/../libc/locale/localeconv.c:63
63              int i = strtol(str, NULL, 10);
(gdb) s
strtol (nptr=0x8054a0d "\177", endptr=0x0, base=10)
    at /mnt1/devel/work/dev/bsd/FreeBSD/src/lib/libc/../libc/stdlib/strtol.c:69
69              s = nptr;
(gdb) s
71                      c = *s++;
(gdb) s
72              } while (isspace((unsigned char)c));
(gdb) s
152             return ((_c < 0 || _c >= _CACHED_RUNES) ___runetype(_c) :
(gdb) s
72              } while (isspace((unsigned char)c));

73              if (c == '-') {
(gdb) s
77                      neg = 0;
(gdb) s
78                      if (c == '+')
(gdb) s
81              if ((base == 0 || base == 16) &&
(gdb) s
87              if (base == 0)
(gdb) s
89              acc = any = 0;
(gdb) s
90              if (base < 2 || base > 36)
(gdb) s
110             cutoff = neg (unsigned long)-(LONG_MIN + LONG_MAX) + LONG_MAX
(gdb) s
113             cutoff /= base;
(gdb) s
114             for ( ; ; c = *s++) {
(gdb) s
115                     if (c >= '0' && c <= '9')
(gdb) s
117                     else if (c >= 'A' && c <= 'Z')
(gdb) s
119                     else if (c >= 'a' && c <= 'z')
(gdb) s
133             if (any < 0) {
(gdb) s
138                     errno = EINVAL;
(gdb) s
__error_unthreaded ()
    at /mnt1/devel/work/dev/bsd/FreeBSD/src/lib/libc/../libc/sys/__error.c:48
48              return(&errno);
(gdb) s
strtol (nptr=0x8054a0d "\177", endptr=0x0, base=10)
    at /mnt1/devel/work/dev/bsd/FreeBSD/src/lib/libc/../libc/stdlib/strtol.c:139
139             } else if (neg)
(gdb) s
141             if (endptr != NULL)
(gdb) s
143             return (acc);
(gdb) s
cnv (str=0x8054a0d "\177")
    at /mnt1/devel/work/dev/bsd/FreeBSD/src/lib/libc/../libc/locale/localeconv.c:64
64              if (i == -1)
(gdb) s
66              return (char)i;
(gdb) s
localeconv ()
    at /mnt1/devel/work/dev/bsd/FreeBSD/src/lib/libc/../libc/locale/localeconv.c:93
93              M_ASSIGN_CHAR(frac_digits);
(gdb) s
cnv (str=0x8054a0d "\177")
    at /mnt1/devel/work/dev/bsd/FreeBSD/src/lib/libc/../libc/locale/localeconv.c:63
63              int i = strtol(str, NULL, 10);
(gdb)p str
$3 = 0x8054a0d "\177"
(gdb) p errno
$4 = 22

--8t9RHnE3ZwKMSgU+--

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-arch" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020127161626.A62332>