Buffer::Iterator::Write (buffer, size) should have a uint32_t parameter, not
uint16_t, else integer overflow may occur. Fixes bug #54.
--- a/src/common/buffer.cc Wed Jul 18 17:43:45 2007 -0400
+++ b/src/common/buffer.cc Thu Jul 19 12:48:22 2007 +0100
@@ -440,6 +440,7 @@
#ifdef RUN_SELF_TESTS
#include "ns3/test.h"
+#include "ns3/random-variable.h"
#include <iomanip>
namespace ns3 {
@@ -501,14 +502,14 @@
uint8_t bytes[] = {__VA_ARGS__}; \
if (!EnsureWrittenBytes (buffer, n , bytes)) \
{ \
- ok = false; \
+ result = false; \
} \
}
bool
BufferTest::RunTests (void)
{
- bool ok = true;
+ bool result = true;
Buffer buffer;
Buffer::Iterator i;
buffer.AddAtStart (6);
@@ -555,7 +556,7 @@
i.Prev (2);
if (i.ReadNtohU16 () != 0xff00)
{
- ok = false;
+ result = false;
}
i.Prev (2);
i.WriteU16 (saved);
@@ -645,7 +646,7 @@
buffer.RemoveAtEnd (8);
if (buffer.GetSize () != 0)
{
- ok = false;
+ result = false;
}
buffer = Buffer (6);
@@ -669,7 +670,31 @@
i.Prev (100);
i.WriteU8 (1, 100);
- return ok;
+ // Bug #54
+ {
+ const uint32_t actualSize = 72602;
+ const uint32_t chunkSize = 67624;
+ UniformVariable bytesRng (0, 256);
+
+ Buffer inputBuffer;
+ Buffer outputBuffer;
+
+ inputBuffer.AddAtEnd (actualSize);
+ {
+ Buffer::Iterator iter = inputBuffer.Begin ();
+ for (uint32_t i = 0; i < actualSize; i++)
+ iter.WriteU8 (static_cast<uint8_t> (bytesRng.GetValue ()));
+ }
+
+ outputBuffer.AddAtEnd (chunkSize);
+ Buffer::Iterator iter = outputBuffer.End ();
+ iter.Prev (chunkSize);
+ iter.Write (inputBuffer.PeekData (), chunkSize);
+
+ NS_TEST_ASSERT (memcmp (inputBuffer.PeekData (), outputBuffer.PeekData (), chunkSize) == 0);
+ }
+
+ return result;
}
--- a/src/common/buffer.h Wed Jul 18 17:43:45 2007 -0400
+++ b/src/common/buffer.h Thu Jul 19 12:48:22 2007 +0100
@@ -158,7 +158,7 @@
* Write the data in buffer and avance the iterator position
* by size bytes.
*/
- inline void Write (uint8_t const*buffer, uint16_t size);
+ inline void Write (uint8_t const*buffer, uint32_t size);
/**
* \param start the start of the data to copy
* \param end the end of the data to copy
@@ -621,7 +621,7 @@
m_current += 8;
}
void
-Buffer::Iterator::Write (uint8_t const*buffer, uint16_t size)
+Buffer::Iterator::Write (uint8_t const*buffer, uint32_t size)
{
uint8_t *current = m_data + GetIndex (size);
memcpy (current, buffer, size);