[Boost-bugs] [Boost C++ Libraries] #11204: undefined behavior sanitizer complains about serialization/singleton.hpp thrown before main()

Subject: [Boost-bugs] [Boost C++ Libraries] #11204: undefined behavior sanitizer complains about serialization/singleton.hpp thrown before main()
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2015-04-18 20:18:04


#11204: undefined behavior sanitizer complains about serialization/singleton.hpp
thrown before main()
-------------------------------------+---------------------------
 Reporter: Georg Sauthoff <mail@…> | Owner: ramey
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: serialization
  Version: Boost Development Trunk | Severity: Problem
 Keywords: |
-------------------------------------+---------------------------
 How to reproduce:

 {{{
 #include <boost/archive/text_iarchive.hpp>
 #include <boost/archive/text_oarchive.hpp>
 #include <boost/serialization/vector.hpp>

 #include <vector>
 #include <fstream>

 using namespace std;

 struct Data {
   vector<int> v;
 };

 namespace boost {
   namespace serialization {

     template<class Archive>
       void serialize(Archive & a, Data &d, const unsigned int version)
       {
         a & d.v;
       }

   }
 }

 int main(int argc, char **argv)
 {
   if (argc > 10) {
     ifstream f("/dev/null");
     boost::archive::text_iarchive a(f);
     Data d;
     a >> d;
   } else {
     ofstream f("/dev/null");
     boost::archive::text_oarchive a(f);
     Data d;
     a << d;
   }
   return 0;
 }
 }}}

 Compile via:

 {{{
 $ g++ -g -std=c++11 -I/home/juser/src/boost/modular-boost \
    -L/home/juser/src/boost/modular-boost/stage/lib \
    -Wl,-R/home/juser/src/boost/modular-boost/stage/lib \
    -fsanitize=undefined test_serialize.cc \
    -o test_serialize -lboost_serialization
 }}}

 (GCC's undefined behavior sanitizer is enabled with
 {{{-fsanitize=undefined}}})

 Run:

 {{{
 $ ./test_serialize
 }}}

 Expected output:

 {{{
 }}}

 (nothing)

 Actual output:

 {{{
 /home/juser/src/boost/modular-
 boost/boost/serialization/singleton.hpp:132:21:
     runtime error: reference binding to null pointer of type
     'const struct extended_type_info_typeid'
 /home/juser/src/boost/modular-
 boost/boost/serialization/singleton.hpp:132:21:
     runtime error: reference binding to null pointer of type
     'const struct iserializer'
 /home/juser/src/boost/modular-
 boost/boost/serialization/singleton.hpp:132:21: runtime error: reference
 binding to null pointer of type 'const struct oserializer'
 /home/juser/src/boost/modular-
 boost/boost/serialization/singleton.hpp:132:21: runtime error: reference
 binding to null pointer of type 'const struct extended_type_info_typeid'
 /home/juser/src/boost/modular-
 boost/boost/serialization/singleton.hpp:132:21: runtime error: reference
 binding to null pointer of type 'const struct oserializer'
 /home/juser/src/boost/modular-
 boost/boost/serialization/singleton.hpp:132:21: runtime error: reference
 binding to null pointer of type 'const struct iserializer'
 }}}

 First backtrace when breaking in singleton.hpp:132:

 {{{
 (gdb) bt
 #0
 boost::serialization::singleton<boost::serialization::extended_type_info_typeid<Data>
>::get_instance ()
     at /home/juser/src/boost/modular-
 boost/boost/serialization/singleton.hpp:132
 #1 0x0000000000407ebd in
 boost::serialization::singleton<boost::serialization::extended_type_info_typeid<Data>
>::get_const_instance ()
     at /home/juser/src/boost/modular-
 boost/boost/serialization/singleton.hpp:141
 #2 0x0000000000407924 in
 boost::archive::detail::iserializer<boost::archive::text_iarchive,
 Data>::iserializer (
     this=0x640a60
 <boost::serialization::singleton<boost::archive::detail::iserializer<boost::archive::text_iarchive,
 Data> >::get_instance()::t>)
     at /home/juser/src/boost/modular-
 boost/boost/archive/detail/iserializer.hpp:128
 #3 0x0000000000407373 in
 boost::serialization::detail::singleton_wrapper<boost::archive::detail::iserializer<boost::archive::text_iarchive,
 Data> >::singleton_wrapper (
     this=0x640a60
 <boost::serialization::singleton<boost::archive::detail::iserializer<boost::archive::text_iarchive,
 Data> >::get_instance()::t>)
     at /home/juser/src/boost/modular-
 boost/boost/serialization/singleton.hpp:106
 #4 0x000000000040740b in
 boost::serialization::singleton<boost::archive::detail::iserializer<boost::archive::text_iarchive,
 Data> >::get_instance ()
     at /home/juser/src/boost/modular-
 boost/boost/serialization/singleton.hpp:128
 #5 0x0000000000404a13 in __static_initialization_and_destruction_0
 (__initialize_p=1, __priority=65535)
     at /home/juser/src/boost/modular-
 boost/boost/serialization/singleton.hpp:149
 #6 0x0000000000404c6e in _GLOBAL__sub_I_main () at test_serialize.cc:43
 #7 0x000000000041abbd in __libc_csu_init ()
 #8 0x00007ffff62e5f6f in __libc_start_main (main=0x4047c6 <main(int,
 char**)>, argc=1, argv=0x7fffffffdfb8, init=0x41ab70 <__libc_csu_init>,
 fini=<optimized out>,
     rtld_fini=<optimized out>, stack_end=0x7fffffffdfa8) at libc-
 start.c:245
 #9 0x00000000004046f9 in _start ()
 }}}

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/11204>
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:18 UTC