bugs in 1-33-1 iostreams non_blocking_adapter.hpp

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; }
participants (1)
-
George M. Garner Jr.