Re: [Boost-bugs] [Boost C++ Libraries] #10228: boost::filesystem::path::parent_path crashes with static link

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #10228: boost::filesystem::path::parent_path crashes with static link
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2014-07-27 19:11:32


#10228: boost::filesystem::path::parent_path crashes with static link
-------------------------------+------------------------
  Reporter: hzj_jie@… | Owner: bemandawes
      Type: Bugs | Status: closed
 Milestone: To Be Determined | Component: filesystem
   Version: Boost 1.55.0 | Severity: Problem
Resolution: worksforme | Keywords:
-------------------------------+------------------------

Comment (by Hzj_jie <hzj_jie@…>):

 detail frame is
 {{{
 #0 0x0000000000431555 in std::locale::locale(std::locale const&) ()
 #1 0x0000000000403ce4 in boost::filesystem::path::imbue (loc=...) at
 libs/filesystem/src/path.cpp:918
 #2 0x0000000000403c57 in boost::filesystem::path::codecvt () at
 libs/filesystem/src/path.cpp:911
 #3 0x0000000000404200 in boost::filesystem::path::path<char const*>
 (this=0x7fffffffe3e0, begin=0x767bd8 "/root/a.out",
     end=0x767bdd "/a.out") at ./boost/filesystem/path.hpp:167
 #4 0x000000000040249f in boost::filesystem::path::parent_path
 (this=0x7fffffffe3d0) at libs/filesystem/src/path.cpp:352
 #5 0x0000000000401509 in run () at exeinfo.cpp:32
 #6 0x00000000004019a7 in ABC::ABC (this=0x74de60 <ABC::instance()::i>) at
 exeinfo.cpp:41
 #7 0x00000000004019df in ABC::instance () at exeinfo.cpp:47
 #8 0x00000000004016d5 in __static_initialization_and_destruction_0
 (__initialize_p=1, __priority=65535) at exeinfo.cpp:50
 #9 0x00000000004016f1 in _GLOBAL__sub_I_main () at exeinfo.cpp:55
 #10 0x000000000045d5e7 in __libc_csu_init ()
 #11 0x000000000045d089 in __libc_start_main ()
 #12 0x00000000004012d7 in _start ()
 }}}

 according to std lib implementation, the copy constructor of locale will
 copy the _M_impl pointer and add reference to it.
 {{{
 00058 locale::locale(const locale& __other) throw()
 00059 : _M_impl(__other._M_impl)
 00060 { _M_impl->_M_add_reference(); }
 }}}

 so if the path_locale._M_impl is nullptr, i.e. the constructor of
 path_locale has not been called, the copy constructor will crash.
 when the user trying to use static variable in functions, the logic may
 call the path::imbue before the constructor of path_locale, and cause the
 trouble.

 i have tried to provide a fix, the principle is to define path_locale as a
 static variable in a function just as what windows implementation does.
 which can resolve the bug. the diff is,
 {{{
 root_at_hzj-ubuntu-1c:~# diff
 downloads/boost_1_55_0/libs/filesystem/src/path.cpp path.cpp
 868,872c868
 < inline std::locale path_locale() // initialized by path::codecvt()
 below
 < {
 < static std::locale loc;
 < return loc;
 < }
 ---
> std::locale path_locale; // initialized by path::codecvt() below
 922,923c918,919
 < std::locale temp(path_locale());
 < path_locale() = loc;
 ---
> std::locale temp(path_locale);
> path_locale = loc;
 925c921
 < &std::use_facet<std::codecvt<wchar_t, char, std::mbstate_t>
>(path_locale());
 ---
> &std::use_facet<std::codecvt<wchar_t, char, std::mbstate_t>
>(path_locale);
 }}}
 would you please have a look, if the proposal works?

 thank you.

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/10228#comment:6>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:16 UTC