|
Boost : |
From: George M. Garner Jr. (gmgarner_at_[hidden])
Date: 2006-08-13 18:41:12
Today I ran into two bugs in non_blocking_adapter.hpp. The code quoted
below results for both read() and write() results in an endless loop if
iostreams::read() or iostreams::write(), respectively, returns 0. Also,
since std::streamsize is an integer, the code in both places should check
for amt < 0. The correct algorithm in both cases is:
if(amt <= 0)
break
Regards,
George.
starting line 26:
std::streamsize read(char_type* s, std::streamsize n)
{
std::streamsize result = 0;
while (result < n) {
std::streamsize amt = iostreams::read(device_, s, n);
if (amt == -1)
break;
result += amt; //<-- infinite loop if amt == 0
}
return result != 0 ? result : -1;
}
std::streamsize write(const char_type* s, std::streamsize n)
{
std::streamsize result = 0;
while (result < n) {
std::streamsize amt =
iostreams::write(device_, s + result, n - result);
result += amt; // <-- infinite loop if amt == 0
}
return result;
}
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk