public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/40184]  New: locale(const char* std_name) can create invalid facets for nonuniform locale
@ 2009-05-18 11:31 tsyvarev at ispras dot ru
  2009-05-18 12:40 ` [Bug libstdc++/40184] " paolo dot carlini at oracle dot com
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: tsyvarev at ispras dot ru @ 2009-05-18 11:31 UTC (permalink / raw)
  To: gcc-bugs

Constructor locale(const char* std_name), when called with name of nonuniform
locale (like "LC_CTYPE=...;LC_COLLATE=...;..."), can create locale with
incorrect content of some its facets: these facets differ from facets of
locale, created via locale(const locale& other, const char* std_name, category)
with subsequent replacing of categories. While this locale has same name as
argument of locale(const char* std_name). 

This behaviour contradicts description of member-function name() (22.1.1.3,
p5):

If *this has a name, then locale(name().c_str()) is equivalent to *this.

Example below demonstrates contradiction of this statement on curr_symbol()
property of moneypunct<wchar_t> facet:

#include <locale>
#include <cassert>

int main()
{
    using namespace std;

    locale loc(locale("C"), "en_GB.utf8", locale::monetary);
    const moneypunct<wchar_t>& mp = 
        use_facet<moneypunct<wchar_t> >(loc);

    locale loc_copy(loc.name().c_str());
    const moneypunct<wchar_t>& mp_copy = 
        use_facet<moneypunct<wchar_t> >(loc_copy);

    assert(mp.curr_symbol() == mp_copy.curr_symbol());

    return 0;
}

It seems, the source of the problem is a method of filling properties of named
locale. E.g., for moneypunct<wchar_t> facet, the method performs the following:
1)sets the current POSIX locale with given name,
2)sets some properties of C++ locale, using __nl_langinfo_l() function call,
3)the rest properties of C++ locale are obtained from char-versions of them
using mbsrtowcs()-like functions.

But mbsrtowcs() use current LC_CTYPE category, which name may differ from the
name of LC_MONETARY category in nonuniform locale. So mbsrtowcs() assumes that
string, passed to it, belongs to one charset(according to LC_TYPE category
name), while it belongs to the another (according to LC_MONETARY category
name).
This fact entails wrong property value, obtained via such call to mbsrtowcs().
Up to garbage, because implementation doesn't verify result of mbsrtowcs(),
which doesn't set terminating '\0' in case of error.

The fact, that the implementation doest't verify result of mbsrtowcs(), also
seems strange - absence of terminating '\0' may lead to SIGFAULT.


-- 
           Summary: locale(const char* std_name) can create invalid facets
                    for nonuniform locale
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: tsyvarev at ispras dot ru


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40184


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug libstdc++/40184] locale(const char* std_name) can create invalid facets for nonuniform locale
  2009-05-18 11:31 [Bug libstdc++/40184] New: locale(const char* std_name) can create invalid facets for nonuniform locale tsyvarev at ispras dot ru
@ 2009-05-18 12:40 ` paolo dot carlini at oracle dot com
  2009-05-18 14:37 ` tsyvarev at ispras dot ru
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: paolo dot carlini at oracle dot com @ 2009-05-18 12:40 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from paolo dot carlini at oracle dot com  2009-05-18 12:40 -------
Ok. Then, what do you think, would it be at least an improvement, constructing
on the fly a uniform locale corresponding to the LC_MONETARY category and
switching to it instead, before calling mbsrtowcs? Performance-wise, should not
be a big issue, because of caching.


-- 

paolo dot carlini at oracle dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |paolo dot carlini at oracle
                   |                            |dot com
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2009-05-18 12:40:14
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40184


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug libstdc++/40184] locale(const char* std_name) can create invalid facets for nonuniform locale
  2009-05-18 11:31 [Bug libstdc++/40184] New: locale(const char* std_name) can create invalid facets for nonuniform locale tsyvarev at ispras dot ru
  2009-05-18 12:40 ` [Bug libstdc++/40184] " paolo dot carlini at oracle dot com
@ 2009-05-18 14:37 ` tsyvarev at ispras dot ru
  2009-05-18 15:04 ` paolo dot carlini at oracle dot com
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: tsyvarev at ispras dot ru @ 2009-05-18 14:37 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from tsyvarev at ispras dot ru  2009-05-18 14:37 -------
Yes, this seems reasonably. I also thought about smth. similar to this. Only it
is need to take into account using mbsrtowcs for other locale properties(if
they exist in others categories).

Anyway, checking of mbsrtowcs result could be usefull, at least for terminate
resulting string with '\0' if mbsrtowcs cannot convert input string for some
reason. E.g., there is a system where mbsrtowcs() cannot convert every
non-ASCII character, but all other locale features work correctly.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40184


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug libstdc++/40184] locale(const char* std_name) can create invalid facets for nonuniform locale
  2009-05-18 11:31 [Bug libstdc++/40184] New: locale(const char* std_name) can create invalid facets for nonuniform locale tsyvarev at ispras dot ru
  2009-05-18 12:40 ` [Bug libstdc++/40184] " paolo dot carlini at oracle dot com
  2009-05-18 14:37 ` tsyvarev at ispras dot ru
@ 2009-05-18 15:04 ` paolo dot carlini at oracle dot com
  2009-05-19 18:21 ` paolo at gcc dot gnu dot org
  2009-05-19 18:24 ` paolo dot carlini at oracle dot com
  4 siblings, 0 replies; 6+ messages in thread
From: paolo dot carlini at oracle dot com @ 2009-05-18 15:04 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from paolo dot carlini at oracle dot com  2009-05-18 15:03 -------
Ok, thanks.


-- 

paolo dot carlini at oracle dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|paolo dot carlini at oracle |
                   |dot com                     |
         AssignedTo|unassigned at gcc dot gnu   |paolo dot carlini at oracle
                   |dot org                     |dot com
             Status|NEW                         |ASSIGNED


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40184


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug libstdc++/40184] locale(const char* std_name) can create invalid facets for nonuniform locale
  2009-05-18 11:31 [Bug libstdc++/40184] New: locale(const char* std_name) can create invalid facets for nonuniform locale tsyvarev at ispras dot ru
                   ` (2 preceding siblings ...)
  2009-05-18 15:04 ` paolo dot carlini at oracle dot com
@ 2009-05-19 18:21 ` paolo at gcc dot gnu dot org
  2009-05-19 18:24 ` paolo dot carlini at oracle dot com
  4 siblings, 0 replies; 6+ messages in thread
From: paolo at gcc dot gnu dot org @ 2009-05-19 18:21 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from paolo at gcc dot gnu dot org  2009-05-19 18:20 -------
Subject: Bug 40184

Author: paolo
Date: Tue May 19 18:20:47 2009
New Revision: 147714

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=147714
Log:
2009-05-19  Paolo Carlini  <paolo.carlini@oracle.com>

        PR libstdc++/40184
        * include/bits/locale_classes.h (locale::facet::_S_lc_ctype_c_locale):
        Declare...
        * config/locale/gnu/c_locale.cc: ... and define.
        * config/locale/generic/c_locale.cc: Define.
        * src/localename.cc (locale::_Impl::_Impl(const char*, size_t)):
        Use it.
        * testsuite/22_locale/locale/cons/40184.cc: New.

Added:
    trunk/libstdc++-v3/testsuite/22_locale/locale/cons/40184.cc
Modified:
    trunk/libstdc++-v3/ChangeLog
    trunk/libstdc++-v3/config/locale/generic/c_locale.cc
    trunk/libstdc++-v3/config/locale/gnu/c_locale.cc
    trunk/libstdc++-v3/include/bits/locale_classes.h
    trunk/libstdc++-v3/src/localename.cc


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40184


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug libstdc++/40184] locale(const char* std_name) can create invalid facets for nonuniform locale
  2009-05-18 11:31 [Bug libstdc++/40184] New: locale(const char* std_name) can create invalid facets for nonuniform locale tsyvarev at ispras dot ru
                   ` (3 preceding siblings ...)
  2009-05-19 18:21 ` paolo at gcc dot gnu dot org
@ 2009-05-19 18:24 ` paolo dot carlini at oracle dot com
  4 siblings, 0 replies; 6+ messages in thread
From: paolo dot carlini at oracle dot com @ 2009-05-19 18:24 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from paolo dot carlini at oracle dot com  2009-05-19 18:24 -------
Fixed.


-- 

paolo dot carlini at oracle dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |4.5.0


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40184


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2009-05-19 18:24 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-05-18 11:31 [Bug libstdc++/40184] New: locale(const char* std_name) can create invalid facets for nonuniform locale tsyvarev at ispras dot ru
2009-05-18 12:40 ` [Bug libstdc++/40184] " paolo dot carlini at oracle dot com
2009-05-18 14:37 ` tsyvarev at ispras dot ru
2009-05-18 15:04 ` paolo dot carlini at oracle dot com
2009-05-19 18:21 ` paolo at gcc dot gnu dot org
2009-05-19 18:24 ` paolo dot carlini at oracle dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).