From: Paolo Carlini Date: Sat, 7 Aug 2004 13:48:31 +0000 (+0000) Subject: c_locale.h (__convert_from_v): Don't use a default for __prec, assume __prec >= 0... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=49864a8255efafcce754540709efe5b4e28eea7b;p=gcc.git c_locale.h (__convert_from_v): Don't use a default for __prec, assume __prec >= 0 and simplify. 2004-08-07 Paolo Carlini * config/locale/generic/c_locale.h (__convert_from_v): Don't use a default for __prec, assume __prec >= 0 and simplify. * config/locale/gnu/c_locale.h (__convert_from_v): Likewise. * include/bits/locale_facets.tcc (money_put<>::do_put(long double)): Pass format "%.*Lf" + precision == 0, equivalent to "%.0Lf". From-SVN: r85669 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 8a811a8412b..597aa665d1a 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,11 @@ +2004-08-07 Paolo Carlini + + * config/locale/generic/c_locale.h (__convert_from_v): Don't + use a default for __prec, assume __prec >= 0 and simplify. + * config/locale/gnu/c_locale.h (__convert_from_v): Likewise. + * include/bits/locale_facets.tcc (money_put<>::do_put(long double)): + Pass format "%.*Lf" + precision == 0, equivalent to "%.0Lf". + 2004-08-04 Phil Edwards * docs/html/configopts.html: Emphasize that options change. diff --git a/libstdc++-v3/config/locale/generic/c_locale.h b/libstdc++-v3/config/locale/generic/c_locale.h index 9fadcc4d99c..a1a56868613 100644 --- a/libstdc++-v3/config/locale/generic/c_locale.h +++ b/libstdc++-v3/config/locale/generic/c_locale.h @@ -57,24 +57,17 @@ namespace std __convert_from_v(char* __out, const int __size __attribute__((__unused__)), const char* __fmt, - _Tv __v, const __c_locale&, int __prec = -1) + _Tv __v, const __c_locale&, int __prec) { char* __old = std::setlocale(LC_ALL, NULL); char* __sav = new char[std::strlen(__old) + 1]; std::strcpy(__sav, __old); std::setlocale(LC_ALL, "C"); - int __ret; #ifdef _GLIBCXX_USE_C99 - if (__prec >= 0) - __ret = std::snprintf(__out, __size, __fmt, __prec, __v); - else - __ret = std::snprintf(__out, __size, __fmt, __v); + const int __ret = std::snprintf(__out, __size, __fmt, __prec, __v); #else - if (__prec >= 0) - __ret = std::sprintf(__out, __fmt, __prec, __v); - else - __ret = std::sprintf(__out, __fmt, __v); + const int __ret = std::sprintf(__out, __fmt, __prec, __v); #endif std::setlocale(LC_ALL, __sav); delete [] __sav; diff --git a/libstdc++-v3/config/locale/gnu/c_locale.h b/libstdc++-v3/config/locale/gnu/c_locale.h index fe899cfc2a5..b6082a2e3fc 100644 --- a/libstdc++-v3/config/locale/gnu/c_locale.h +++ b/libstdc++-v3/config/locale/gnu/c_locale.h @@ -68,11 +68,11 @@ namespace std int __convert_from_v(char* __out, const int __size, const char* __fmt, #if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2) - _Tv __v, const __c_locale& __cloc, int __prec = -1) + _Tv __v, const __c_locale& __cloc, int __prec) { __c_locale __old = __gnu_cxx::__uselocale(__cloc); #else - _Tv __v, const __c_locale&, int __prec = -1) + _Tv __v, const __c_locale&, int __prec) { char* __old = std::setlocale(LC_ALL, NULL); char* __sav = new char[std::strlen(__old) + 1]; @@ -80,17 +80,10 @@ namespace std std::setlocale(LC_ALL, "C"); #endif - int __ret; #ifdef _GLIBCXX_USE_C99 - if (__prec >= 0) - __ret = std::snprintf(__out, __size, __fmt, __prec, __v); - else - __ret = std::snprintf(__out, __size, __fmt, __v); + const int __ret = std::snprintf(__out, __size, __fmt, __prec, __v); #else - if (__prec >= 0) - __ret = std::sprintf(__out, __fmt, __prec, __v); - else - __ret = std::sprintf(__out, __fmt, __v); + const int __ret = std::sprintf(__out, __fmt, __prec, __v); #endif #if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2) diff --git a/libstdc++-v3/include/bits/locale_facets.tcc b/libstdc++-v3/include/bits/locale_facets.tcc index ee5ea7d1def..f5fd21ba796 100644 --- a/libstdc++-v3/include/bits/locale_facets.tcc +++ b/libstdc++-v3/include/bits/locale_facets.tcc @@ -1689,22 +1689,22 @@ namespace std char* __cs = static_cast(__builtin_alloca(__cs_size)); // _GLIBCXX_RESOLVE_LIB_DEFECTS // 328. Bad sprintf format modifier in money_put<>::do_put() - int __len = std::__convert_from_v(__cs, __cs_size, "%.0Lf", __units, - _S_get_c_locale()); + int __len = std::__convert_from_v(__cs, __cs_size, "%.*Lf", __units, + _S_get_c_locale(), 0); // If the buffer was not large enough, try again with the correct size. if (__len >= __cs_size) { __cs_size = __len + 1; __cs = static_cast(__builtin_alloca(__cs_size)); - __len = std::__convert_from_v(__cs, __cs_size, "%.0Lf", __units, - _S_get_c_locale()); + __len = std::__convert_from_v(__cs, __cs_size, "%.*Lf", __units, + _S_get_c_locale(), 0); } #else // max_exponent10 + 1 for the integer part, + 2 for sign and '\0'. const int __cs_size = numeric_limits::max_exponent10 + 3; char* __cs = static_cast(__builtin_alloca(__cs_size)); - int __len = std::__convert_from_v(__cs, 0, "%.0Lf", __units, - _S_get_c_locale()); + int __len = std::__convert_from_v(__cs, 0, "%.*Lf", __units, + _S_get_c_locale(), 0); #endif _CharT* __ws = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * __cs_size));