|
Bugzilla – Full Text Bug Listing |
| Summary: | Buffer::CopyData() doesn't return the number of bytes copied | ||
|---|---|---|---|
| Product: | ns-3 | Reporter: | Bill Roome <wdr> |
| Component: | network | Assignee: | Mathieu Lacage <mathieu.lacage> |
| Status: | PATCH PENDING --- | ||
| Severity: | normal | CC: | frederic.urbani, mathieu.lacage, ns-bugs, pdbarnes, vedran |
| Priority: | P5 | ||
| Version: | ns-3.9 | ||
| Hardware: | All | ||
| OS: | All | ||
| Attachments: |
proposed approach for fix
Buffer::CopyData patch and testcase buffer patch Add testcase for this bug fix |
||
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 |
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. }