Bug 1001

Summary: Buffer::CopyData() doesn't return the number of bytes copied
Product: ns-3 Reporter: Bill Roome <wdr>
Component: networkAssignee: 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

Description Bill Roome 2010-10-05 14:24:07 EDT
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,

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.
Comment 1 Mathieu Lacage 2011-07-06 18:17:45 EDT
Created attachment 1190 [details]
proposed approach for fix
Comment 2 Mathieu Lacage 2011-07-06 18:18:19 EDT
it would be helpful if you could test the untested attached patch. Also, a testcase for buffer-test.cc would be most welcome.
Comment 3 Mathieu Lacage 2011-09-10 02:18:31 EDT
*** Bug 1261 has been marked as a duplicate of this bug. ***
Comment 4 Frederic Urbani 2011-09-12 05:19:43 EDT
Created attachment 1242 [details]
Buffer::CopyData  patch and testcase

The patch 1190 seems not to deal with buffer ?
Comment 5 Mathieu Lacage 2011-09-12 09:39:10 EDT
Created attachment 1243 [details]
buffer patch

yes, the original patch included a bunch of garbage together with the patch.
Comment 6 Frederic Urbani 2011-09-12 10:18:30 EDT
Created attachment 1244 [details]
Add testcase for this bug fix

+1 for this testcase + the patch 1243.
Comment 7 Peter Barnes 2019-11-04 17:28:58 EST
This is a network issue, not core