Bugzilla – Bug 1001
Buffer::CopyData() doesn't return the number of bytes copied
Last modified: 2019-11-04 17:28:58 UTC
Buffer::CopyData (uint8_t*, uint32_t) does not return the total number of bytes copied. I'm not sure of the best way to fix it, but my suggestion is to keep a copy of the original buffer pointer, increment buffer after the final memcpy(), and return the difference between the final and original values of buffer. Eg, uint32_t Buffer::CopyData (uint8_t *buffer, uint32_t size) const { /** * ALU CHANGE: Calculate the copied byte count as the difference * between the final value of "buffer" and the original value. */ uint8_t* originalBuffer = buffer; if (size > 0) { uint32_t tmpsize = std::min (m_zeroAreaStart-m_start, size); memcpy (buffer, (const char*)(m_data->m_data + m_start), tmpsize); buffer += tmpsize; if (size > tmpsize) { size -= m_zeroAreaStart-m_start; tmpsize = std::min (m_zeroAreaEnd - m_zeroAreaStart, size); uint32_t left = tmpsize; while (left > 0) { uint32_t toWrite = std::min (left, g_zeroes.size); memcpy (buffer, g_zeroes.buffer, toWrite); left -= toWrite; buffer += toWrite; } if (size > tmpsize) { size -= tmpsize; tmpsize = std::min (m_end - m_zeroAreaEnd, size); memcpy (buffer, (const char*)(m_data->m_data + m_zeroAreaStart), tmpsize); buffer += tmpsize; // ALU: Added this statement } } } return buffer - originalBuffer; // ALU: was originalSize - size. }
Created attachment 1190 [details] proposed approach for fix
it would be helpful if you could test the untested attached patch. Also, a testcase for buffer-test.cc would be most welcome.
*** Bug 1261 has been marked as a duplicate of this bug. ***
Created attachment 1242 [details] Buffer::CopyData patch and testcase The patch 1190 seems not to deal with buffer ?
Created attachment 1243 [details] buffer patch yes, the original patch included a bunch of garbage together with the patch.
Created attachment 1244 [details] Add testcase for this bug fix +1 for this testcase + the patch 1243.
This is a network issue, not core