Opened 15 years ago
Closed 15 years ago
#1070 closed Bugs (fixed)
[iostreams]boost\iostreams\copy.hpp line80 copy_impl
| Reported by: | Owned by: | Jonathan Turkanis | |
|---|---|---|---|
| Milestone: | To Be Determined | Component: | iostreams |
| Version: | Boost 1.34.0 | Severity: | Problem |
| Keywords: | Cc: |
Description
boost\iostreams\copy.hpp line 80 - line 100
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; }
When "iostreams::read" return -1 ,amt equal -1,it will assert in std::copy because iterator last < first.
Please read http://article.gmane.org/gmane.comp.lib.boost.devel/161764 for detail.
Change History (7)
comment:1 by , 15 years ago
comment:3 by , 15 years ago
The proposed change at ticket #786 seems a little cleaner than the change here.
comment:4 by , 15 years ago
| Component: | None → iostreams |
|---|---|
| Owner: | set to |
| Severity: | Showstopper → Problem |
comment:6 by , 15 years ago
| Owner: | set to |
|---|
comment:7 by , 15 years ago
| Resolution: | → fixed |
|---|---|
| Status: | new → closed |
Note:
See TracTickets
for help on using tickets.

.hpp
bool done = false;while (!done) {streamsize amt;done = (amt = iostreams::read(src, buf.data(), buffer_size)) == -1;--- copy.hpp 2005-05-26 01:37:30.000000000 +0800 +++ copy1.hpp 2007-07-06 15:55:17.859375000 +0800 @@ -88,13 +88,12 @@ 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; + while (true) { + streamsize amt = iostreams::read(src, buf.data(), buffer_size); + if(amt == -1) + break; std::copy(buf.data(), buf.data() + amt, p.first + total); - if (amt != -1) - total += amt; + total += amt; } return total; } @@ -109,14 +108,12 @@ detail::basic_buffer<char_type> buf(buffer_size); non_blocking_adapter<Sink> nb(snk); std::streamsize total = 0; - bool done = false; - while (!done) { - std::streamsize amt; - done = (amt = iostreams::read(src, buf.data(), buffer_size)) == -1; - if (amt != -1) { - iostreams::write(nb, buf.data(), amt); - total += amt; - } + while (true) { + std::streamsize amt = iostreams::read(src, buf.data(), buffer_size); + if (amt == -1) + break; + iostreams::write(nb, buf.data(), amt); + total += amt; } return total; }