From 332604fd02bc64baaba0d13feaf401d8a36cca44 Mon Sep 17 00:00:00 2001 From: Quincy Tse Date: Wed, 10 Aug 2011 13:09:23 -0400 Subject: [PATCH] bug 1050: ISO C++ forbids variable length array --- src/applications/model/ping6.cc | 4 +- src/applications/model/v4ping.cc | 6 ++- src/internet/model/icmpv6-header.cc | 15 +++++--- src/internet/model/icmpv6-l4-protocol.cc | 3 +- src/internet/model/ipv6-extension-header.cc | 6 ++- src/network/utils/packetbb.cc | 42 ++++++++++++++------- 6 files changed, 52 insertions(+), 24 deletions(-) diff --git a/src/applications/model/ping6.cc b/src/applications/model/ping6.cc index 1dfa8de5a..8a75f0603 100644 --- a/src/applications/model/ping6.cc +++ b/src/applications/model/ping6.cc @@ -162,7 +162,7 @@ void Ping6::Send () NS_LOG_FUNCTION_NOARGS (); NS_ASSERT (m_sendEvent.IsExpired ()); Ptr p = 0; - uint8_t data[m_size]; + uint8_t* data = new uint8_t[m_size]; Ipv6Address src; Ptr ipv6 = GetNode ()->GetObject (); @@ -221,6 +221,8 @@ void Ping6::Send () { ScheduleTransmit (m_interval); } + + delete[] data; } void Ping6::HandleRead (Ptr socket) diff --git a/src/applications/model/v4ping.cc b/src/applications/model/v4ping.cc index 93c6fdad0..1e057f45e 100644 --- a/src/applications/model/v4ping.cc +++ b/src/applications/model/v4ping.cc @@ -123,7 +123,7 @@ V4Ping::Receive (Ptr 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) } } } + 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 diff --git a/src/internet/model/icmpv6-header.cc b/src/internet/model/icmpv6-header.cc index 85cba19b2..ef548bea8 100644 --- a/src/internet/model/icmpv6-header.cc +++ b/src/internet/model/icmpv6-header.cc @@ -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 (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 (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 (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 (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 (buff, len2); + delete[] buff; return GetSerializedSize (); } diff --git a/src/internet/model/icmpv6-l4-protocol.cc b/src/internet/model/icmpv6-l4-protocol.cc index f85fb0ff3..9cd9cb299 100644 --- a/src/internet/model/icmpv6-l4-protocol.cc +++ b/src/internet/model/icmpv6-l4-protocol.cc @@ -232,7 +232,7 @@ void Icmpv6L4Protocol::HandleEchoRequest (Ptr 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, 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, Ipv6Address const &src, Ipv6Address const &dst, Ptr interface) diff --git a/src/internet/model/ipv6-extension-header.cc b/src/internet/model/ipv6-extension-header.cc index 05b00408d..2db006346 100644 --- a/src/internet/model/ipv6-extension-header.cc +++ b/src/internet/model/ipv6-extension-header.cc @@ -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; } diff --git a/src/network/utils/packetbb.cc b/src/network/utils/packetbb.cc index 329af15a7..3cba0850b 100644 --- a/src/network/utils/packetbb.cc +++ b/src/network/utils/packetbb.cc @@ -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);