Boost C++ Libraries: Ticket #5765: Container Device/Sink bug https://svn.boost.org/trac10/ticket/5765 <p> i think write should be like this, otherwise if one seeks back (after writing to overwrite replace some data, number of bytes seeked back will be duplicated on the next write. (original line changed/replaced is commented out in code) </p> <div class="wiki-code"><div class="code"><pre> <span class="n">std</span><span class="o">::</span><span class="n">streamsize</span> <span class="n">write</span><span class="p">(</span><span class="k">const</span> <span class="n">char_type</span><span class="o">*</span> <span class="n">s</span><span class="p">,</span> <span class="n">std</span><span class="o">::</span><span class="n">streamsize</span> <span class="n">n</span><span class="p">)</span> <span class="p">{</span> <span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span> <span class="n">std</span><span class="o">::</span><span class="n">streamsize</span> <span class="n">result</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="k">if</span> <span class="p">(</span><span class="n">pos_</span> <span class="o">!=</span> <span class="n">container_</span><span class="p">.</span><span class="n">size</span><span class="p">())</span> <span class="p">{</span> <span class="n">std</span><span class="o">::</span><span class="n">streamsize</span> <span class="n">amt</span> <span class="o">=</span> <span class="k">static_cast</span><span class="o">&lt;</span><span class="n">std</span><span class="o">::</span><span class="n">streamsize</span><span class="o">&gt;</span><span class="p">(</span><span class="n">container_</span><span class="p">.</span><span class="n">size</span><span class="p">()</span> <span class="o">-</span> <span class="n">pos_</span><span class="p">);</span> <span class="n">result</span> <span class="o">=</span> <span class="p">(</span><span class="n">min</span><span class="p">)(</span><span class="n">n</span><span class="p">,</span> <span class="n">amt</span><span class="p">);</span> <span class="n">std</span><span class="o">::</span><span class="n">copy</span><span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="n">s</span> <span class="o">+</span> <span class="n">result</span><span class="p">,</span> <span class="n">container_</span><span class="p">.</span><span class="n">begin</span><span class="p">()</span> <span class="o">+</span> <span class="n">pos_</span><span class="p">);</span> <span class="n">pos_</span> <span class="o">+=</span> <span class="n">result</span><span class="p">;</span> <span class="p">}</span> <span class="k">if</span> <span class="p">(</span><span class="n">result</span> <span class="o">&lt;</span> <span class="n">n</span><span class="p">)</span> <span class="p">{</span> <span class="n">container_</span><span class="p">.</span><span class="n">insert</span><span class="p">(</span><span class="n">container_</span><span class="p">.</span><span class="n">end</span><span class="p">(),</span> <span class="n">s</span> <span class="o">+</span> <span class="n">result</span><span class="p">,</span> <span class="n">s</span> <span class="o">+</span> <span class="n">n</span><span class="p">);</span> <span class="c1">//container_.insert(container_.end(), s, s + n);</span> <span class="n">pos_</span> <span class="o">=</span> <span class="n">container_</span><span class="p">.</span><span class="n">size</span><span class="p">();</span> <span class="p">}</span> <span class="k">return</span> <span class="n">n</span><span class="p">;</span> <span class="p">}</span> </pre></div></div> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/5765 Trac 1.4.3