diff --git a/src/network/model/packet-metadata.cc b/src/network/model/packet-metadata.cc index fbeaa6458..987ab9c91 100644 --- a/src/network/model/packet-metadata.cc +++ b/src/network/model/packet-metadata.cc @@ -612,11 +612,11 @@ struct PacketMetadata::Data * PacketMetadata::Allocate (uint32_t n) { uint32_t size = sizeof (struct Data); - if (n <= 10) + if (n <= PACKET_METADATA_DATA_M_DATA_SIZE) { - n = 10; + n = PACKET_METADATA_DATA_M_DATA_SIZE; } - size += n - 10; + size += n - PACKET_METADATA_DATA_M_DATA_SIZE; uint8_t *buf = new uint8_t [size]; struct PacketMetadata::Data *data = (struct PacketMetadata::Data *)buf; data->m_size = n; diff --git a/src/network/model/packet-metadata.h b/src/network/model/packet-metadata.h index 547362d8f..1e4d3dd5a 100644 --- a/src/network/model/packet-metadata.h +++ b/src/network/model/packet-metadata.h @@ -22,6 +22,7 @@ #include #include +#include #include "ns3/callback.h" #include "ns3/assert.h" #include "ns3/type-id.h" @@ -208,16 +209,23 @@ private: const uint8_t* start, const uint8_t* current, uint32_t maxSize); + + /** + * the size of PacketMetadata::Data::m_data such that the total size + * of PacketMetadata::Data is 16 bytes + */ +#define PACKET_METADATA_DATA_M_DATA_SIZE 8 + struct Data { /* number of references to this struct Data instance. */ - uint16_t m_count; + uint32_t m_count; /* size (in bytes) of m_data buffer below */ uint16_t m_size; /* max of the m_used field over all objects which * reference this struct Data instance */ uint16_t m_dirtyEnd; /* variable-sized buffer of bytes */ - uint8_t m_data[10]; + uint8_t m_data[PACKET_METADATA_DATA_M_DATA_SIZE]; }; /* Note that since the next and prev fields are 16 bit integers and since the value 0xffff is reserved to identify the @@ -376,6 +384,7 @@ PacketMetadata::PacketMetadata (PacketMetadata const &o) m_packetUid (o.m_packetUid) { NS_ASSERT (m_data != 0); + NS_ASSERT (m_data->m_count < std::numeric_limits::max()); m_data->m_count++; } PacketMetadata &