Boost logo

Boost :

From: Mathieu Peyréga (mathieu.peyrega_at_[hidden])
Date: 2006-12-09 16:29:57


Hello,

i'm a new user to these great boost libraries...
I think i found a bug in <boost/iostreams/copy.hpp> (version 1.33.1)

the current code starting line 80 is

template<typename Source, typename Sink>
std::streamsize copy_impl( Source& src, Sink& snk,
                           std::streamsize buffer_size,
                           mpl::false_, mpl::true_ )
{ // Copy from an indirect Source to a direct Sink.
    using namespace std;
    typedef typename char_type_of<Source>::type char_type;
    typedef pair<char_type*, char_type*> pair_type;
    detail::basic_buffer<char_type> buf(buffer_size);
    pair_type p = snk.output_sequence();
    streamsize total = 0;
    bool done = false;
    while (!done) {
        streamsize amt;
        done = (amt = iostreams::read(src, buf.data(), buffer_size)) == -1;
        std::copy(buf.data(), buf.data() + amt, p.first + total);
        if (amt != -1)
            total += amt;
    }
    return total;
}

I think it should be somthing like

template<typename Source, typename Sink>
std::streamsize copy_impl( Source& src, Sink& snk,
                           std::streamsize buffer_size,
                           mpl::false_, mpl::true_ )
{ // Copy from an indirect Source to a direct Sink.
    using namespace std;
    typedef typename char_type_of<Source>::type char_type;
    typedef pair<char_type*, char_type*> pair_type;
    detail::basic_buffer<char_type> buf(buffer_size);
    pair_type p = snk.output_sequence();
    streamsize total = 0;
    streamsize amt = 0;
    //bool done = false;
    while ((amt = iostreams::read(src, buf.data(),buffer_size))!= -1) {
        std::copy(buf.data(), buf.data() + amt, p.first + total);
        total += amt;
    }
    return total;
}

The current code happens to crash whereas the proposed version works
properly... Did I miss something or a I right ?

Regards,

Mathieu

-- 
 <http://matioupi.free.fr/> http://matioupi.free.fr/ 

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk