Skip to content

Commit

Permalink
Merge pull request #6 from steven-martins/master
Browse files Browse the repository at this point in the history
bugfix : xsputn // taking into consideration the buffer size when copying
  • Loading branch information
achille-roussel committed May 16, 2016
2 parents 031724a + 88fc3ed commit bfa97c1
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/nnxx/message_streambuf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,22 @@ namespace nnxx {
basic_message_streambuf<Char, Traits>::xsputn(const char_type *s, streamsize n)
{
using std::copy;

if (n > static_cast<streamsize>(this->epptr() - this->pptr())) {
overflow(traits_type::eof());
streamsize ret = 0;

while (ret < n) {
streamsize buflen = static_cast<streamsize>(this->epptr() - this->pptr());

if (buflen) {
streamsize len = std::min(buflen, n - ret);
copy(s, s + len, this->pptr());
this->pbump(len);
ret += len;
s += len;
}
if (ret < n)
overflow(traits_type::eof());
}

copy(s, s + n, this->pptr());
this->pbump(n);
return n;
return ret;
}

template < typename Char, typename Traits >
Expand Down

0 comments on commit bfa97c1

Please sign in to comment.