There appears to be a bug in strfom.c, function __setup_vars. When the value for the negative sign string is fetched, there are two comparisons of the following style: *signstr = (lc->negative_sign == '\0') ? "-" : lc->negative_sign; lc->negative_sign is a string pointer. The above statement compares the pointer against '\0'. This looks like a typo. Actually the comparison should check if the first character in lc->negative_sign is \0, or better, if lc->negative_sign is an empty string. A check for NULL doesn't make sense since localeconv never returns NULL pointers as struct lconv members. So I think the patch below should be the right way to go. Corinna
Author: cracauer Date: Wed Feb 10 00:02:09 2010 New Revision: 203734 URL: http://svn.freebsd.org/changeset/base/203734 Log: Fix PR http://www.freebsd.org/cgi/query-pr.cgi?pr=bin/143350 Empty string test gone wrong. Testing this requires that you have a locale that has the sign string unset but has int_n_sign_posn set (the default locale falls through to use "()" around negative numbers which is probably another bug). I created that setup by hand and indeed without this fix negative numbers are put out as positive numbers (doesn't fall through to use "-" as default indicator). Unfixed example in nl_NL.ISO8859-1 with lc->negative_sign set to empty string: strfmon(buf, sizeof(buf), "%-8i", -42.0); ==> example2: 'EUR 42,00' 'Eu 42,00' Fixed: example2: 'EUR 42,00-' 'Eu 42,00-' This file and suggested fix are identical in at least freebsd-8. Backport might be appropriate but some expert on locales should probably have a look at us defaulting to negative numbers in parenthesis when LC_* is default. That doesn't look right and is not what other OSes are doing. PR: 143350 Submitted by: Corinna Vinschen Reviewed by: bug reporter submitted, tested by me Modified: head/lib/libc/stdlib/strfmon.c Modified: head/lib/libc/stdlib/strfmon.c ============================================================================== --- head/lib/libc/stdlib/strfmon.c Wed Feb 10 00:01:35 2010 (r203733) +++ head/lib/libc/stdlib/strfmon.c Wed Feb 10 00:02:09 2010 (r203734) @@ -413,7 +413,7 @@ __setup_vars(int flags, char *cs_precede *cs_precedes = lc->int_n_cs_precedes; *sep_by_space = lc->int_n_sep_by_space; *sign_posn = (flags & PARENTH_POSN) ? 0 : lc->int_n_sign_posn; - *signstr = (lc->negative_sign == '\0') ? "-" + *signstr = (lc->negative_sign[0] == '\0') ? "-" : lc->negative_sign; } else if (flags & USE_INTL_CURRENCY) { *cs_precedes = lc->int_p_cs_precedes; @@ -424,7 +424,7 @@ __setup_vars(int flags, char *cs_precede *cs_precedes = lc->n_cs_precedes; *sep_by_space = lc->n_sep_by_space; *sign_posn = (flags & PARENTH_POSN) ? 0 : lc->n_sign_posn; - *signstr = (lc->negative_sign == '\0') ? "-" + *signstr = (lc->negative_sign[0] == '\0') ? "-" : lc->negative_sign; } else { *cs_precedes = lc->p_cs_precedes; _______________________________________________ svn-src-all@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/svn-src-all To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
State Changed From-To: open->closed Fixed in -current as suggested after testing, commit r203734. Let me know if backports are desired.