public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/40712]  New: locale(const locale&, const char*, locale::category) can create broken locale
@ 2009-07-10 12:56 tsyvarev at ispras dot ru
  2009-07-10 21:14 ` [Bug libstdc++/40712] " 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-07-10 12:56 UTC (permalink / raw)
  To: gcc-bugs

This code causes SIGFAULT on Ubuntu 8.10:

#include <locale>
using namespace std;

int main()
{
    locale loc(locale("C"), "en_US", locale::monetary);
    use_facet<moneypunct<char> >(loc).grouping();
    return 0;
}

Tested both with native gcc and one builded from svn.
According to gdb, sigfault is caused by strlen while converting c-string to
c++-string when returns from moneypunct<char>::do_grouping().

andrew@andrew-desktop:~/work/test$ gcc --version
gcc (Ubuntu 4.3.2-1ubuntu12) 4.3.2
Copyright (C) 2008 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

andrew@andrew-desktop:~/work/test$ /home/andrew/gcc/bin/gcc --version
gcc (GCC) 4.5.0 20090709 (experimental)
Copyright (C) 2009 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

andrew@andrew-desktop:~/work/test$ g++ test.cpp && ./a.out
Segmentation fault


-- 
           Summary: locale(const locale&, const char*, locale::category) can
                    create broken 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=40712


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

* [Bug libstdc++/40712] locale(const locale&, const char*, locale::category) can create broken locale
  2009-07-10 12:56 [Bug libstdc++/40712] New: locale(const locale&, const char*, locale::category) can create broken locale tsyvarev at ispras dot ru
@ 2009-07-10 21:14 ` paolo dot carlini at oracle dot com
  2009-07-11 19:43 ` paolo dot carlini at oracle dot com
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: paolo dot carlini at oracle dot com @ 2009-07-10 21:14 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from paolo dot carlini at oracle dot com  2009-07-10 21:14 -------
By the way, sEgfault, not sIgfault.


-- 

paolo dot carlini at oracle dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |paolo dot carlini at oracle
                   |dot org                     |dot com
             Status|UNCONFIRMED                 |ASSIGNED
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2009-07-10 21:14:43
               date|                            |


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


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

* [Bug libstdc++/40712] locale(const locale&, const char*, locale::category) can create broken locale
  2009-07-10 12:56 [Bug libstdc++/40712] New: locale(const locale&, const char*, locale::category) can create broken locale tsyvarev at ispras dot ru
  2009-07-10 21:14 ` [Bug libstdc++/40712] " paolo dot carlini at oracle dot com
@ 2009-07-11 19:43 ` paolo dot carlini at oracle dot com
  2009-07-13 11:55 ` tsyvarev at ispras dot ru
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: paolo dot carlini at oracle dot com @ 2009-07-11 19:43 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from paolo dot carlini at oracle dot com  2009-07-11 19:43 -------
I think this constructor never ever worked correctly. The only solution I can
see at the moment is consistently dynamically allocating _M_data->_M_grouping,
and copying the characters of __nl_langinfo_l(__MON_GROUPING, __cloc) into it
as part of _M_initialize_moneypunct. The same for the other C strings, for
numpunct too, of course. Isn't such a big issue, after all, but I'm rather
surprised that we didn't notice the issue much earlier: destroying the __cloc
at the end of locale::_Impl::_Impl(const char*, size_t) after having referred
to the various __nl_langinfo_l(..., __cloc) in _M_initialize_moneypunct without
actually copying the data should unavoidably cause problems...


-- 

paolo dot carlini at oracle dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bkoz at redhat dot com


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


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

* [Bug libstdc++/40712] locale(const locale&, const char*, locale::category) can create broken locale
  2009-07-10 12:56 [Bug libstdc++/40712] New: locale(const locale&, const char*, locale::category) can create broken locale tsyvarev at ispras dot ru
  2009-07-10 21:14 ` [Bug libstdc++/40712] " paolo dot carlini at oracle dot com
  2009-07-11 19:43 ` paolo dot carlini at oracle dot com
@ 2009-07-13 11:55 ` tsyvarev at ispras dot ru
  2009-07-18 22:58 ` paolo at gcc dot gnu dot org
  2009-08-03  9:25 ` paolo dot carlini at oracle dot com
  4 siblings, 0 replies; 6+ messages in thread
From: tsyvarev at ispras dot ru @ 2009-07-13 11:55 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from tsyvarev at ispras dot ru  2009-07-13 11:55 -------
(In reply to comment #2)
> I think this constructor never ever worked correctly. The only solution I can
> see at the moment is consistently dynamically allocating _M_data->_M_grouping,
> and copying the characters of __nl_langinfo_l(__MON_GROUPING, __cloc) into it
> as part of _M_initialize_moneypunct.
Reasonable solution. Actually, I thougth that _M_initialize_moneypunct had
already implemented in such way.

As for "we didn't notice the issue much earlier" - it is strange, but in many
other cases locale, created with this constructor, behaves correctly(at least,
does not cause program to abort and remains internal properties). And this case
crashes program not on every system.


-- 


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


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

* [Bug libstdc++/40712] locale(const locale&, const char*, locale::category) can create broken locale
  2009-07-10 12:56 [Bug libstdc++/40712] New: locale(const locale&, const char*, locale::category) can create broken locale tsyvarev at ispras dot ru
                   ` (2 preceding siblings ...)
  2009-07-13 11:55 ` tsyvarev at ispras dot ru
@ 2009-07-18 22:58 ` paolo at gcc dot gnu dot org
  2009-08-03  9:25 ` paolo dot carlini at oracle dot com
  4 siblings, 0 replies; 6+ messages in thread
From: paolo at gcc dot gnu dot org @ 2009-07-18 22:58 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from paolo at gcc dot gnu dot org  2009-07-18 22:58 -------
Subject: Bug 40712

Author: paolo
Date: Sat Jul 18 22:58:10 2009
New Revision: 149782

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

        PR libstdc++/40712
        * config/locale/gnu/numeric_members.cc (numpunct<>::
        _M_initialize_numpunct): Dynamically allocate _M_data->_M_grouping
        and copy the langinfo data into it.
        (numpunct<>::~numpunct): Free the allocated memory.
        * config/locale/gnu/monetary_members.cc (moneypunct<>::
        _M_initialize_moneypunct): Dynamically allocate _M_data->_M_grouping,
        _M_data->_M_positive_sign, _M_data->_M_negative_sign,
        _M_data->_M_curr_symbol.
        (moneypunct<>::~moneypunct): Free the allocated memory.
        * testsuite/22_locale/moneypunct/40712.cc: New.

        * include/bits/locale_facets.tcc (__numpunct_cache<>::_M_cache):
        Do not leak memory if new throws.
        * include/bits/locale_facets_nonio.tcc
        (__moneypunct_cache<>::_M_cache): Likewise.

Added:
    trunk/libstdc++-v3/testsuite/22_locale/moneypunct/40712.cc
Modified:
    trunk/libstdc++-v3/ChangeLog
    trunk/libstdc++-v3/config/locale/gnu/monetary_members.cc
    trunk/libstdc++-v3/config/locale/gnu/numeric_members.cc
    trunk/libstdc++-v3/include/bits/locale_facets.tcc
    trunk/libstdc++-v3/include/bits/locale_facets_nonio.tcc


-- 


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


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

* [Bug libstdc++/40712] locale(const locale&, const char*, locale::category) can create broken locale
  2009-07-10 12:56 [Bug libstdc++/40712] New: locale(const locale&, const char*, locale::category) can create broken locale tsyvarev at ispras dot ru
                   ` (3 preceding siblings ...)
  2009-07-18 22:58 ` paolo at gcc dot gnu dot org
@ 2009-08-03  9:25 ` paolo dot carlini at oracle dot com
  4 siblings, 0 replies; 6+ messages in thread
From: paolo dot carlini at oracle dot com @ 2009-08-03  9:25 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from paolo dot carlini at oracle dot com  2009-08-03 09:24 -------
Unless there are many requests, let's not fix this for gcc-4_4-branch, isn't a
regression and nobody noticed for many years...


-- 

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=40712


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

end of thread, other threads:[~2009-08-03  9:25 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-07-10 12:56 [Bug libstdc++/40712] New: locale(const locale&, const char*, locale::category) can create broken locale tsyvarev at ispras dot ru
2009-07-10 21:14 ` [Bug libstdc++/40712] " paolo dot carlini at oracle dot com
2009-07-11 19:43 ` paolo dot carlini at oracle dot com
2009-07-13 11:55 ` tsyvarev at ispras dot ru
2009-07-18 22:58 ` paolo at gcc dot gnu dot org
2009-08-03  9:25 ` 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).