Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 28 Jan 2002 08:55:58 +0300
From:      "Andrey A. Chernov" <ache@nagual.pp.ru>
To:        Chad David <davidc@acns.ab.ca>, phantom@FreeBSD.org
Cc:        "Brian F. Feldman" <green@FreeBSD.org>, Bruce Evans <bde@zeta.org.au>, arch@FreeBSD.org
Subject:   Re: strtod()
Message-ID:  <20020128055557.GA23297@nagual.pp.ru>
In-Reply-To: <20020127161626.A62332@colnta.acns.ab.ca>
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> <20020127161626.A62332@colnta.acns.ab.ca>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sun, Jan 27, 2002 at 16:16:26 -0700, Chad David wrote:

> I don't understand what you mean.
> 

This is locale code bug and EINVAL from strtol() really helps to find it.

Try the patch below, it fix the problem (at least on my testing):


--- lmonetary.c.old	Thu Dec 13 12:26:25 2001
+++ lmonetary.c	Mon Jan 28 08:50:21 2002
@@ -27,6 +27,7 @@
  */
 
 #include <limits.h>
+#include <stdlib.h>
 #include "lmonetary.h"
 #include "ldpart.h"
 
@@ -60,6 +61,14 @@
 static int	_monetary_using_locale;
 static char	*_monetary_locale_buf;
 
+static char
+cnv(const char *str) {
+	int i = strtol(str, NULL, 10);
+	if (i == -1)
+		i = CHAR_MAX;
+	return (char)i;
+}
+
 int
 __monetary_load_locale(const char *name) {
 
@@ -69,9 +78,22 @@
 		_monetary_locale_buf, "LC_MONETARY",
 		LCMONETARY_SIZE, LCMONETARY_SIZE,
 		(const char **)&_monetary_locale);
-	if (ret == 0 && _monetary_using_locale)
+	if (ret == 0 && _monetary_using_locale) {
 		_monetary_locale.mon_grouping =
 		     __fix_locale_grouping_str(_monetary_locale.mon_grouping);
+
+#define M_ASSIGN_CHAR(NAME) (((char *)_monetary_locale.NAME)[0] = \
+			     cnv(_monetary_locale.NAME))
+
+		M_ASSIGN_CHAR(int_frac_digits);
+		M_ASSIGN_CHAR(frac_digits);
+		M_ASSIGN_CHAR(p_cs_precedes);
+		M_ASSIGN_CHAR(p_sep_by_space);
+		M_ASSIGN_CHAR(n_cs_precedes);
+		M_ASSIGN_CHAR(n_sep_by_space);
+		M_ASSIGN_CHAR(p_sign_posn);
+		M_ASSIGN_CHAR(n_sign_posn);
+	}
 	return ret;
 }
 
@@ -93,14 +115,14 @@
 	"mon_grouping = %s\n"
 	"positive_sign = %s\n"
 	"negative_sign = %s\n"
-	"int_frac_digits = %s\n"
-	"frac_digits = %s\n"
-	"p_cs_precedes = %s\n"
-	"p_sep_by_space = %s\n"
-	"n_cs_precedes = %s\n"
-	"n_sep_by_space = %s\n"
-	"p_sign_posn = %s\n"
-	"n_sign_posn = %s\n",
+	"int_frac_digits = %d\n"
+	"frac_digits = %d\n"
+	"p_cs_precedes = %d\n"
+	"p_sep_by_space = %d\n"
+	"n_cs_precedes = %d\n"
+	"n_sep_by_space = %d\n"
+	"p_sign_posn = %d\n"
+	"n_sign_posn = %d\n",
 	_monetary_locale.int_curr_symbol,
 	_monetary_locale.currency_symbol,
 	_monetary_locale.mon_decimal_point,
@@ -108,14 +130,14 @@
 	_monetary_locale.mon_grouping,
 	_monetary_locale.positive_sign,
 	_monetary_locale.negative_sign,
-	_monetary_locale.int_frac_digits,
-	_monetary_locale.frac_digits,
-	_monetary_locale.p_cs_precedes,
-	_monetary_locale.p_sep_by_space,
-	_monetary_locale.n_cs_precedes,
-	_monetary_locale.n_sep_by_space,
-	_monetary_locale.p_sign_posn,
-	_monetary_locale.n_sign_posn
+	_monetary_locale.int_frac_digits[0],
+	_monetary_locale.frac_digits[0],
+	_monetary_locale.p_cs_precedes[0],
+	_monetary_locale.p_sep_by_space[0],
+	_monetary_locale.n_cs_precedes[0],
+	_monetary_locale.n_sep_by_space[0],
+	_monetary_locale.p_sign_posn[0],
+	_monetary_locale.n_sign_posn[0]
 );
 }
 #endif /* LOCALE_DEBUG */
--- localeconv.c.old	Fri Dec 21 07:27:35 2001
+++ localeconv.c	Mon Jan 28 08:44:47 2002
@@ -41,8 +41,6 @@
 #endif /* LIBC_SCCS and not lint */
 
 #include <locale.h>
-#include <stdlib.h>
-#include <limits.h>
 #include "lmonetary.h"
 #include "lnumeric.h"
 
@@ -58,14 +56,6 @@
 int __mlocale_changed = 1;
 int __nlocale_changed = 1;
 
-static char
-cnv(char *str) {
-	int i = strtol(str, NULL, 10);
-	if (i == -1)
-		i = CHAR_MAX;
-	return (char)i;
-}
-
 /*
  * Return the current locale conversion.
  */
@@ -79,7 +69,7 @@
         struct lc_monetary_T * mptr; 
 
 #define M_ASSIGN_STR(NAME) (ret.NAME = (char*)mptr->NAME)
-#define M_ASSIGN_CHAR(NAME) (ret.NAME = cnv((char*)mptr->NAME))
+#define M_ASSIGN_CHAR(NAME) (ret.NAME = mptr->NAME[0])
 
 	mptr = __get_current_monetary_locale();
 	M_ASSIGN_STR(int_curr_symbol);


-- 
Andrey A. Chernov
http://ache.pp.ru/

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?20020128055557.GA23297>