Boost logo

Boost Users :

From: Stephen Torri (storri_at_[hidden])
Date: 2007-05-19 17:19:11


I am difficulty determining the location of the segfault in the
following code:

        boost::uint32_t reserve_length = 0;
        
        std::ifstream file_handle_ref ( name.c_str(),
                                        std::ios::binary | std::ios::in );
        
        if ( ! file_handle_ref.is_open() ) // Expecting result of is_open() to be true
            {
                std::cerr << "Error opening " << name << std::endl;
                std::cerr << " " << strerror(errno) << std::endl;
                
                std::cerr << boost::format("Exception throw in %s at line %d")
                    % __FILE__
                    % __LINE__
                          << std::endl;
                
                throw errors::IO_Exception
                    (errors::IO_Exception::FATAL_IO_ERROR);
            }

                
        file_handle_ref.seekg( 0, std::ios::end );
        reserve_length = file_handle_ref.tellg();
        std::cout << "Reserve length = " << reserve_length << std::endl;

        <SEGFAULT>
        std::cout << boost::format ("reserve_length (method 1) = %d") % reserve_length << std::endl;
        </SEGFAULT>

==452== Invalid read of size 4
==452== at 0x480228C3: std::ostreambuf_iterator<char, std::char_traits<char> > std::num_put<char, std::ostreambuf_iterator<char, std::char_traits<char> > >::_M_insert_int<unsigned long>(std::ostreambuf_iterator<char, std::char_traits<char> >, std::ios_base&, char, unsigned long) const (in /usr/lib/libstdc++.so.6.0.8)
==452== by 0x48022BAF: std::num_put<char, std::ostreambuf_iterator<char, std::char_traits<char> > >::do_put(std::ostreambuf_iterator<char, std::char_traits<char> >, std::ios_base&, char, unsigned long) const (in /usr/lib/libstdc++.so.6.0.8)
==452== by 0x4802B63C: std::ostream::operator<<(unsigned) (in /usr/lib/libstdc++.so.6.0.8)
==452== by 0x4197E59: void boost::io::detail::put_last<char, std::char_traits<char>, unsigned>(std::basic_ostream<char, std::char_traits<char> >&, unsigned&) (feed_args.hpp:113)
==452== by 0x4197F85: void boost::io::detail::put<char, std::char_traits<char>, std::allocator<char>, unsigned&>(unsigned&, boost::io::detail::format_item<char, std::char_traits<char>, std::allocator<char> > const&, boost::basic_format<char, std::char_traits<char>, std::allocator<char> >::string_type&, std::char_traits<char>::internal_streambuf_t&, std::locale*) (feed_args.hpp:150)
==452== by 0x4198724: void boost::io::detail::distribute<char, std::char_traits<char>, std::allocator<char>, unsigned&>(boost::basic_format<char, std::char_traits<char>, std::allocator<char> >&, unsigned&) (feed_args.hpp:241)
==452== by 0x4198783: boost::basic_format<char, std::char_traits<char>, std::allocator<char> >& boost::io::detail::feed<char, std::char_traits<char>, std::allocator<char>, unsigned&>(boost::basic_format<char, std::char_traits<char>, std::allocator<char> >&, unsigned&) (feed_args.hpp:251)
==452== by 0x4198849: boost::basic_format<char, std::char_traits<char>, std::allocator<char> >& boost::basic_format<char, std::char_traits<char>, std::allocator<char> >::operator%<unsigned>(unsigned&) (format_class.hpp:68)
==452== by 0x41940EE: libreverse::data_container::Memory_Map::Memory_Map(std::string, unsigned) (Memory_Map.cpp:87)
==452== by 0x41D2D85: libreverse::io::File::read_Image() (File.cpp:119)
==452== by 0x41D30F1: libreverse::io::File::init() (File.cpp:151)
==452== by 0x8089A2B: libreverse::wpef_module::PE_File<32>::init() (PE_File_T.cpp:48)
==452== Address 0x30 is not stack'd, malloc'd or (recently) free'd
==452==

I made a driver program for this line. The driver works fine.

        #include <boost/cstdint.hpp>
        #include <boost/format.hpp>
        #include <iostream>
        #include <fstream>
        
        int main (int, char**)
        {
                boost::uint32_t reserve_length = 0;
                std::ifstream input_ref ( "kernel32.dll", std::ios::binary |
        std::ios::in );
        
                input_ref.seekg ( 0, std::ios::end );
                reserve_length = input_ref.tellg();
        
                std::cout << boost::format("Something done %d") %
        reserve_length << std::endl;
        }
        
So I cannot provide you an easy example. I am sorry about this. I hope I
am asking an intelligent question.

Stephen
        


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net