bug 1050: ISO C++ forbids variable length array

This commit is contained in:
Quincy Tse
2011-08-10 13:09:23 -04:00
parent e56f6b64c9
commit 332604fd02
6 changed files with 52 additions and 24 deletions

View File

@@ -162,7 +162,7 @@ void Ping6::Send ()
NS_LOG_FUNCTION_NOARGS ();
NS_ASSERT (m_sendEvent.IsExpired ());
Ptr<Packet> p = 0;
uint8_t data[m_size];
uint8_t* data = new uint8_t[m_size];
Ipv6Address src;
Ptr<Ipv6> ipv6 = GetNode ()->GetObject<Ipv6> ();
@@ -221,6 +221,8 @@ void Ping6::Send ()
{
ScheduleTransmit (m_interval);
}
delete[] data;
}
void Ping6::HandleRead (Ptr<Socket> socket)

View File

@@ -123,7 +123,7 @@ V4Ping::Receive (Ptr<Socket> socket)
if (i != m_sent.end () && echo.GetIdentifier () == 0)
{
uint32_t buf[m_size / 4];
uint32_t * buf = new uint32_t [m_size / 4];
uint32_t dataSize = echo.GetDataSize ();
uint32_t nodeId;
uint32_t appId;
@@ -154,6 +154,7 @@ V4Ping::Receive (Ptr<Socket> socket)
}
}
}
delete[] buf;
}
}
}
@@ -193,7 +194,7 @@ V4Ping::Send ()
// (where any difference would show up anyway) and borrow that code. Don't
// be too surprised when you see that this is a little endian convention.
//
uint8_t data[m_size];
uint8_t* data = new uint8_t[m_size];
for (uint32_t i = 0; i < m_size; ++i) data[i] = 0;
NS_ASSERT (m_size >= 16);
@@ -217,6 +218,7 @@ V4Ping::Send ()
m_sent.insert (std::make_pair (m_seq - 1, Simulator::Now ()));
m_socket->Send (p, 0);
m_next = Simulator::Schedule (m_interval, &V4Ping::Send, this);
delete[] data;
}
void

View File

@@ -1008,7 +1008,7 @@ void Icmpv6DestinationUnreachable::Serialize (Buffer::Iterator start) const
uint32_t Icmpv6DestinationUnreachable::Deserialize (Buffer::Iterator start)
{
uint16_t length = start.GetSize () - 8;
uint8_t data[length];
uint8_t* data = new uint8_t[length];
Buffer::Iterator i = start;
SetType (i.ReadU8 ());
@@ -1018,6 +1018,7 @@ uint32_t Icmpv6DestinationUnreachable::Deserialize (Buffer::Iterator start)
i.Read (data, length);
m_packet = Create<Packet> (data, length);
delete[] data;
return GetSerializedSize ();
}
@@ -1106,7 +1107,7 @@ void Icmpv6TooBig::Serialize (Buffer::Iterator start) const
uint32_t Icmpv6TooBig::Deserialize (Buffer::Iterator start)
{
uint16_t length = start.GetSize () - 8;
uint8_t data[length];
uint8_t* data = new uint8_t[length];
Buffer::Iterator i = start;
SetType (i.ReadU8 ());
@@ -1116,6 +1117,7 @@ uint32_t Icmpv6TooBig::Deserialize (Buffer::Iterator start)
i.Read (data, length);
m_packet = Create<Packet> (data, length);
delete[] data;
return GetSerializedSize ();
}
@@ -1193,7 +1195,7 @@ void Icmpv6TimeExceeded::Serialize (Buffer::Iterator start) const
uint32_t Icmpv6TimeExceeded::Deserialize (Buffer::Iterator start)
{
uint16_t length = start.GetSize () - 8;
uint8_t data[length];
uint8_t* data = new uint8_t[length];
Buffer::Iterator i = start;
SetType (i.ReadU8 ());
@@ -1203,6 +1205,7 @@ uint32_t Icmpv6TimeExceeded::Deserialize (Buffer::Iterator start)
i.Read (data, length);
m_packet = Create<Packet> (data, length);
delete[] data;
return GetSerializedSize ();
}
@@ -1291,7 +1294,7 @@ void Icmpv6ParameterError::Serialize (Buffer::Iterator start) const
uint32_t Icmpv6ParameterError::Deserialize (Buffer::Iterator start)
{
uint16_t length = start.GetSize () - 8;
uint8_t data[length];
uint8_t* data = new uint8_t[length];
Buffer::Iterator i = start;
SetType (i.ReadU8 ());
@@ -1300,6 +1303,7 @@ uint32_t Icmpv6ParameterError::Deserialize (Buffer::Iterator start)
SetPtr (i.ReadNtohU32 ());
i.Read (data, length);
m_packet = Create<Packet> (data, length);
delete[] data;
return GetSerializedSize ();
}
@@ -1777,9 +1781,10 @@ uint32_t Icmpv6OptionRedirected::Deserialize (Buffer::Iterator start)
i.ReadU32 ();
uint32_t len2 = (GetLength () - 1) * 8;
uint8_t buff[len2];
uint8_t* buff = new uint8_t[len2];
i.Read (buff, len2);
m_packet = Create<Packet> (buff, len2);
delete[] buff;
return GetSerializedSize ();
}

View File

@@ -232,7 +232,7 @@ void Icmpv6L4Protocol::HandleEchoRequest (Ptr<Packet> packet, Ipv6Address const
{
NS_LOG_FUNCTION (this << packet << src << dst << interface);
Icmpv6Echo request;
uint8_t buf[packet->GetSize ()];
uint8_t* buf = new uint8_t[packet->GetSize ()];
packet->RemoveHeader (request);
/* XXX IPv6 extension: obtain a fresh copy of data otherwise it crash... */
@@ -241,6 +241,7 @@ void Icmpv6L4Protocol::HandleEchoRequest (Ptr<Packet> packet, Ipv6Address const
/* if we send message from ff02::* (link-local multicast), we use our link-local address */
SendEchoReply (dst.IsMulticast () ? interface->GetLinkLocalAddress ().GetAddress () : dst, src, request.GetId (), request.GetSeq (), p);
delete[] buf;
}
void Icmpv6L4Protocol::HandleRA (Ptr<Packet> packet, Ipv6Address const &src, Ipv6Address const &dst, Ptr<Ipv6Interface> interface)

View File

@@ -102,7 +102,7 @@ uint32_t Ipv6ExtensionHeader::Deserialize (Buffer::Iterator start)
m_length = i.ReadU8 ();
uint32_t dataLength = GetLength () - 2;
uint8_t data[dataLength];
uint8_t* data = new uint8_t[dataLength];
i.Read (data, dataLength);
if (dataLength > m_data.GetSize ())
@@ -117,6 +117,7 @@ uint32_t Ipv6ExtensionHeader::Deserialize (Buffer::Iterator start)
i = m_data.Begin ();
i.Write (data, dataLength);
delete[] data;
return GetSerializedSize ();
}
@@ -152,11 +153,12 @@ void OptionField::Serialize (Buffer::Iterator start) const
uint32_t OptionField::Deserialize (Buffer::Iterator start, uint32_t length)
{
uint8_t buf[length];
uint8_t* buf = new uint8_t[length];
start.Read (buf, length);
m_optionData = Buffer ();
m_optionData.AddAtEnd (length);
m_optionData.Begin ().Write (buf, length);
delete[] buf;
return length;
}

View File

@@ -1590,17 +1590,20 @@ PbbMessageIpv4::GetAddressLength (void) const
void
PbbMessageIpv4::SerializeOriginatorAddress (Buffer::Iterator &start) const
{
uint8_t buffer[GetAddressLength () + 1];
uint8_t* buffer = new uint8_t[GetAddressLength () + 1];
Ipv4Address::ConvertFrom (GetOriginatorAddress ()).Serialize (buffer);
start.Write (buffer, GetAddressLength () + 1);
delete[] buffer;
}
Address
PbbMessageIpv4::DeserializeOriginatorAddress (Buffer::Iterator &start) const
{
uint8_t buffer[GetAddressLength () + 1];
uint8_t* buffer = new uint8_t[GetAddressLength () + 1];
start.Read (buffer, GetAddressLength () + 1);
return Ipv4Address::Deserialize (buffer);
Address result = Ipv4Address::Deserialize (buffer);
delete[] buffer;
return result;
}
void
@@ -1636,17 +1639,20 @@ PbbMessageIpv6::GetAddressLength (void) const
void
PbbMessageIpv6::SerializeOriginatorAddress (Buffer::Iterator &start) const
{
uint8_t buffer[GetAddressLength () + 1];
uint8_t* buffer = new uint8_t[GetAddressLength () + 1];
Ipv6Address::ConvertFrom (GetOriginatorAddress ()).Serialize (buffer);
start.Write (buffer, GetAddressLength () + 1);
delete[] buffer;
}
Address
PbbMessageIpv6::DeserializeOriginatorAddress (Buffer::Iterator &start) const
{
uint8_t buffer[GetAddressLength () + 1];
uint8_t* buffer = new uint8_t[GetAddressLength () + 1];
start.Read (buffer, GetAddressLength () + 1);
return Ipv6Address::Deserialize (buffer);
Address res = Ipv6Address::Deserialize (buffer);
delete[] buffer;
return res;
}
void
@@ -1980,9 +1986,9 @@ PbbAddressBlock::GetSerializedSize (void) const
}
else if (AddressSize () > 0)
{
uint8_t head[GetAddressLength ()];
uint8_t* head = new uint8_t[GetAddressLength ()];
uint8_t headlen = 0;
uint8_t tail[GetAddressLength ()];
uint8_t* tail = new uint8_t[GetAddressLength ()];
uint8_t taillen = 0;
GetHeadTail (head, headlen, tail, taillen);
@@ -2005,6 +2011,9 @@ PbbAddressBlock::GetSerializedSize (void) const
size += (GetAddressLength () - headlen - taillen) * AddressSize ();
size += PrefixSize ();
delete[] head;
delete[] tail;
}
size += m_addressTlvList.GetSerializedSize ();
@@ -2022,7 +2031,7 @@ PbbAddressBlock::Serialize (Buffer::Iterator &start) const
if (AddressSize () == 1)
{
uint8_t buf[GetAddressLength ()];
uint8_t* buf = new uint8_t[GetAddressLength ()];
SerializeAddress (buf, AddressBegin ());
start.Write (buf, GetAddressLength ());
@@ -2032,11 +2041,12 @@ PbbAddressBlock::Serialize (Buffer::Iterator &start) const
flags |= AHAS_SINGLE_PRE_LEN;
}
bufref.WriteU8 (flags);
delete[] buf;
}
else if (AddressSize () > 0)
{
uint8_t head[GetAddressLength ()];
uint8_t tail[GetAddressLength ()];
uint8_t* head = new uint8_t[GetAddressLength ()];
uint8_t* tail = new uint8_t[GetAddressLength ()];
uint8_t headlen = 0;
uint8_t taillen = 0;
@@ -2066,7 +2076,7 @@ PbbAddressBlock::Serialize (Buffer::Iterator &start) const
if (headlen + taillen < GetAddressLength ())
{
uint8_t mid[GetAddressLength ()];
uint8_t* mid = new uint8_t[GetAddressLength ()];
for (PbbAddressBlock::ConstAddressIterator iter = AddressBegin ();
iter != AddressEnd ();
iter++)
@@ -2074,6 +2084,7 @@ PbbAddressBlock::Serialize (Buffer::Iterator &start) const
SerializeAddress (mid, iter);
start.Write (mid + headlen, GetAddressLength () - headlen - taillen);
}
delete mid;
}
flags |= GetPrefixFlags ();
@@ -2085,6 +2096,9 @@ PbbAddressBlock::Serialize (Buffer::Iterator &start) const
{
start.WriteU8 (*iter);
}
delete[] head;
delete[] tail;
}
m_addressTlvList.Serialize (start);
@@ -2100,7 +2114,7 @@ PbbAddressBlock::Deserialize (Buffer::Iterator &start)
{
uint8_t headlen = 0;
uint8_t taillen = 0;
uint8_t addrtmp[GetAddressLength ()];
uint8_t* addrtmp = new uint8_t[GetAddressLength ()];
memset (addrtmp, 0, GetAddressLength ());
if (flags & AHAS_HEAD)
@@ -2136,6 +2150,8 @@ PbbAddressBlock::Deserialize (Buffer::Iterator &start)
PrefixPushBack (start.ReadU8 ());
}
}
delete[] addrtmp;
}
m_addressTlvList.Deserialize (start);