Opened 16 years ago

Closed 15 years ago

#786 closed Bugs (fixed)

bug in iostreams/copy.hpp line 81

Reported by: nobody Owned by: Jonathan Turkanis
Milestone: Component: iostreams
Version: None Severity: Problem
Keywords: Cc:

Description

in boost 1_33_1 iostreams library

file copy.hpp

line 91 and following...

it should rather be :

streamsize amt;
while ((amt=iostreams::read(src, buf.data(),buffer_size)) != -1)
{
   std::copy(buf.data(), buf.data() + amt, p.first + total);
   total += amt;
}
return total;

otherwise it happens that the std::copy line is called with amt =-1 which is a bug isnt it ?

Regards,

Mathieu

Change History (7)

comment:1 by alexis_wilke, 16 years ago

Logged In: YES 
user_id=554061
Originator: NO

Mathieu,

Actually, the copy operator will test if(_first < _last) <do the copy> and if amt is -1 that condition will be false. Yet I agree that your way we would avoid one call and one variable ('done' in the original loop). I'm not part of boost so I cannot decide whether to apply the change. But this is only an optimization.

Alexis

comment:2 by anonymous, 15 years ago

There is a patch for this in "official patch format" in: http://article.gmane.org/gmane.comp.lib.boost.user/23522

comment:3 by chris@…, 15 years ago

Alexis,

My copy operator did not perform your test and I saw the bug (5 or 6 levels down the stack a copy for last-first would eventually SIGSEGV in memcpy.)

-

Chris DUrso

in reply to:  1 comment:4 by qbowater@…, 15 years ago

Replying to alexis_wilke:

Mathieu,

Actually, the copy operator will test if(_first < _last) <do the copy> and if amt is -1 that condition will be false. Yet I agree that your way we would avoid one call and one variable ('done' in the original loop). I'm not part of boost so I cannot decide whether to apply the change. But this is only an optimization. Alexis

In VC8 DEBUG mode,it will assert in std::copy because "first > last". It make difficult to debug program.I think it should be repaired necessarily.

comment:5 by anonymous, 15 years ago

This looks like a duplicate of #1070

comment:6 by Daryle Walker, 15 years ago

Component: Noneiostreams
Severity: Problem

comment:7 by Jonathan Turkanis, 15 years ago

Resolution: Nonefixed
Status: assignedclosed

Fixed in [42294] in branches/iostreams_dev, to be merged into trunk shortly. The fix is a slight modification of the suggestion above.

Note: See TracTickets for help on using tickets.