bug 1050: ISO C++ forbids variable length array
authorQuincy Tse <quincy.tse@gmail.com>
Wed, 10 Aug 2011 13:09:23 -0400
changeset 7416 91df05070541
parent 7415 a26626a4f5bf
child 7417 8e695ab6f94a
bug 1050: ISO C++ forbids variable length array
src/applications/model/ping6.cc
src/applications/model/v4ping.cc
src/internet/model/icmpv6-header.cc
src/internet/model/icmpv6-l4-protocol.cc
src/internet/model/ipv6-extension-header.cc
src/network/utils/packetbb.cc
--- a/src/applications/model/ping6.cc	Wed Aug 10 12:39:19 2011 -0400
+++ b/src/applications/model/ping6.cc	Wed Aug 10 13:09:23 2011 -0400
@@ -162,7 +162,7 @@
   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 @@
     {
       ScheduleTransmit (m_interval);
     }
+
+  delete[] data;
 }
 
 void Ping6::HandleRead (Ptr<Socket> socket)
--- a/src/applications/model/v4ping.cc	Wed Aug 10 12:39:19 2011 -0400
+++ b/src/applications/model/v4ping.cc	Wed Aug 10 13:09:23 2011 -0400
@@ -123,7 +123,7 @@
 
           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 @@
                         }
                     }
                 }
+              delete[] buf;
             }
         }
     }
@@ -193,7 +194,7 @@
   // (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 @@
   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 
--- a/src/internet/model/icmpv6-header.cc	Wed Aug 10 12:39:19 2011 -0400
+++ b/src/internet/model/icmpv6-header.cc	Wed Aug 10 13:09:23 2011 -0400
@@ -1008,7 +1008,7 @@
 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 @@
   i.Read (data, length);
   m_packet = Create<Packet> (data, length);
 
+  delete[] data;
   return GetSerializedSize ();
 }
 
@@ -1106,7 +1107,7 @@
 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 @@
   i.Read (data, length);
   m_packet = Create<Packet> (data, length);
 
+  delete[] data;
   return GetSerializedSize ();
 }
 
@@ -1193,7 +1195,7 @@
 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 @@
   i.Read (data, length);
   m_packet = Create<Packet> (data, length);
 
+  delete[] data;
   return GetSerializedSize ();
 }
 
@@ -1291,7 +1294,7 @@
 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 @@
   SetPtr (i.ReadNtohU32 ());
   i.Read (data, length);
   m_packet = Create<Packet> (data, length);
+  delete[] data;
 
   return GetSerializedSize ();
 }
@@ -1777,9 +1781,10 @@
   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 ();
 }
--- a/src/internet/model/icmpv6-l4-protocol.cc	Wed Aug 10 12:39:19 2011 -0400
+++ b/src/internet/model/icmpv6-l4-protocol.cc	Wed Aug 10 13:09:23 2011 -0400
@@ -232,7 +232,7 @@
 {
   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 @@
 
   /* 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)
--- a/src/internet/model/ipv6-extension-header.cc	Wed Aug 10 12:39:19 2011 -0400
+++ b/src/internet/model/ipv6-extension-header.cc	Wed Aug 10 13:09:23 2011 -0400
@@ -102,7 +102,7 @@
   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 @@
   i = m_data.Begin ();
   i.Write (data, dataLength);
 
+  delete[] data;
   return GetSerializedSize ();
 }
 
@@ -152,11 +153,12 @@
 
 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;
 }
 
--- a/src/network/utils/packetbb.cc	Wed Aug 10 12:39:19 2011 -0400
+++ b/src/network/utils/packetbb.cc	Wed Aug 10 13:09:23 2011 -0400
@@ -1590,17 +1590,20 @@
 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 @@
 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 @@
     }
   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 @@
       size += (GetAddressLength () - headlen - taillen) * AddressSize ();
 
       size += PrefixSize ();
+
+      delete[] head;
+      delete[] tail;
     }
 
   size += m_addressTlvList.GetSerializedSize ();
@@ -2022,7 +2031,7 @@
 
   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 @@
           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 @@
 
       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 @@
               SerializeAddress (mid, iter);
               start.Write (mid + headlen, GetAddressLength () - headlen - taillen);
             }
+          delete mid;
         }
 
       flags |= GetPrefixFlags ();
@@ -2085,6 +2096,9 @@
         {
           start.WriteU8 (*iter);
         }
+
+      delete[] head;
+      delete[] tail;
     }
 
   m_addressTlvList.Serialize (start);
@@ -2100,7 +2114,7 @@
     {
       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 @@
               PrefixPushBack (start.ReadU8 ());
             }
         }
+
+      delete[] addrtmp;
     }
 
   m_addressTlvList.Deserialize (start);