Writing after end of available buffer space error.

26 views
Skip to first unread message

Jordan Hedges

unread,
Nov 16, 2018, 3:00:01 AM11/16/18
to ns-3-users
Hi, I am currently experiencing the following error while trying to implement a custom trailer: assert failed. cond="Check (m_current)", msg="You have attempted to write after the end of the available buffer space. This usually indicates that Header::GetSerializedSize returned a size which is too small compared to what Header::Serialize is actually using."

I have tried setting the return value of GetSerializedSize to a ridiculous value and am still encountering this error, so I believe that is not what is currently happening. Below is the relevant custom trailer functions which errors immediately upon attempting start.WriteHtonU64(vectorSize).

Writes the size of the vector to be written to the buffer (in the test case, 3) as a uint64_t then writes the individual uin64_t's in the vector to the buffer.
void ConsensusTrailer::Serialize(Buffer::Iterator start) const{
    std::cerr << "writing size\n";
    start.WriteHtonU64(vectorSize);
    std::cerr << "wrote size\n";
    for(uint64_t i = 0; i < vectorSize; i++)
    {
        start.WriteHtonU64(m_data[i]);
    }   
}

Required size in the buffer is the size of the vector (vectorSize) multiplied by the size of a uint64_t plus an additional uint64_t to write the vectorSize.
uint32_t ConsensusTrailer::GetSerializedSize(void) const
{
    uint32_t dataSize = vectorSize * sizeof (uint64_t) + sizeof(uint64_t);
    return dataSize;
}

Here is the initialisation of the packet trailer, using test data (1, 2, 3) which fails on createdPacket->AddTrailer(packetTrailer). The AddHeader portion seems to work correctly (consists of writing a single uint16_t).
    std::vector<uint64_t> packetData = {1, 2, 3};
    ConsensusTrailer packetTrailer(packetData);
    createdPacket->AddHeader(packetHeader);
   
    createdPacket->AddTrailer(packetTrailer);

Not sure what is going wrong exactly, I have compared it to the example provided in 'src/network/examples/main-packet-header.cc' and other examples that inherit from header and it seems to be similar in the basic construction. Any help would be much appreciated.
Reply all
Reply to author
Forward
0 new messages