[Coverity] Unchecked dynamic_cast (FORWARD_NULL)
authorPeter D. Barnes, Jr. <barnes26@llnl.gov>
Wed, 15 May 2013 15:47:58 -0400
changeset 9784 740a983ed25b
parent 9783 828a38d9c799
child 9785 97052ab05772
[Coverity] Unchecked dynamic_cast (FORWARD_NULL)
src/core/model/object-factory.cc
src/core/model/test.cc
src/internet/model/global-route-manager-impl.cc
src/internet/model/ipv6-extension.cc
src/internet/model/ipv6-l3-protocol.cc
src/internet/model/pending-data.cc
src/wimax/model/simple-ofdm-wimax-phy.cc
--- a/src/core/model/object-factory.cc	Wed May 15 15:17:20 2013 -0400
+++ b/src/core/model/object-factory.cc	Wed May 15 15:47:58 2013 -0400
@@ -92,6 +92,7 @@
   Callback<ObjectBase *> cb = m_tid.GetConstructor ();
   ObjectBase *base = cb ();
   Object *derived = dynamic_cast<Object *> (base);
+  NS_ASSERT (derived != 0);
   derived->SetTypeId (m_tid);
   derived->Construct (m_parameters);
   Ptr<Object> object = Ptr<Object> (derived, false);
--- a/src/core/model/test.cc	Wed May 15 15:17:20 2013 -0400
+++ b/src/core/model/test.cc	Wed May 15 15:47:58 2013 -0400
@@ -654,6 +654,7 @@
   for (std::list<TestCase *>::const_iterator i = begin; i != end; ++i)
     {
       TestSuite * test= dynamic_cast<TestSuite *>(*i);
+      NS_ASSERT (test != 0);
       if (printTestType)
         {
           std::cout << label[test->GetTestType ()];
--- a/src/internet/model/global-route-manager-impl.cc	Wed May 15 15:17:20 2013 -0400
+++ b/src/internet/model/global-route-manager-impl.cc	Wed May 15 15:47:58 2013 -0400
@@ -767,6 +767,7 @@
 // shortest path calculation.
 //
           l = v->GetLSA ()->GetLinkRecord (i);
+          NS_ASSERT (l != 0);
           if (l->GetLinkType () == GlobalRoutingLinkRecord::StubNetwork)
             {
               NS_LOG_LOGIC ("Found a Stub record to " << l->GetLinkId ());
--- a/src/internet/model/ipv6-extension.cc	Wed May 15 15:17:20 2013 -0400
+++ b/src/internet/model/ipv6-extension.cc	Wed May 15 15:47:58 2013 -0400
@@ -530,15 +530,24 @@
         {
           if (it->second == Ipv6Header::IPV6_EXT_HOP_BY_HOP)
             {
-              fragment->AddHeader (*dynamic_cast<Ipv6ExtensionHopByHopHeader *> (it->first));
+              Ipv6ExtensionHopByHopHeader * p =
+                dynamic_cast<Ipv6ExtensionHopByHopHeader *> (it->first);
+              NS_ASSERT (p != 0);
+              fragment->AddHeader (*p);
             }
           else if (it->second == Ipv6Header::IPV6_EXT_ROUTING)
             {
-              fragment->AddHeader (*dynamic_cast<Ipv6ExtensionLooseRoutingHeader *> (it->first));
+              Ipv6ExtensionLooseRoutingHeader * p =
+                dynamic_cast<Ipv6ExtensionLooseRoutingHeader *> (it->first);
+              NS_ASSERT (p != 0);
+              fragment->AddHeader (*p);
             }
           else if (it->second == Ipv6Header::IPV6_EXT_DESTINATION)
             {
-              fragment->AddHeader (*dynamic_cast<Ipv6ExtensionDestinationHeader *> (it->first));
+              Ipv6ExtensionDestinationHeader * p =
+                dynamic_cast<Ipv6ExtensionDestinationHeader *> (it->first);
+              NS_ASSERT (p != 0);
+              fragment->AddHeader (*p);
             }
         }
 
--- a/src/internet/model/ipv6-l3-protocol.cc	Wed May 15 15:17:20 2013 -0400
+++ b/src/internet/model/ipv6-l3-protocol.cc	Wed May 15 15:47:58 2013 -0400
@@ -814,6 +814,7 @@
 
       // To get specific method GetFragments from Ipv6ExtensionFragmentation
       Ipv6ExtensionFragment *ipv6Fragment = dynamic_cast<Ipv6ExtensionFragment *> (PeekPointer (ipv6ExtensionDemux->GetExtension (Ipv6Header::IPV6_EXT_FRAGMENTATION)));
+      NS_ASSERT (ipv6Fragment != 0);
       ipv6Fragment->GetFragments (packet, outInterface->GetDevice ()->GetMtu (), fragments);
     }
 
--- a/src/internet/model/pending-data.cc	Wed May 15 15:17:20 2013 -0400
+++ b/src/internet/model/pending-data.cc	Wed May 15 15:47:58 2013 -0400
@@ -103,7 +103,7 @@
 void PendingData::Add (uint32_t s, const uint8_t* d)
 {
   NS_LOG_FUNCTION (this << s);
-  if (d == 0)
+  if (d != 0)
     {
       data.push_back (Create<Packet> (d,s));
     }
--- a/src/wimax/model/simple-ofdm-wimax-phy.cc	Wed May 15 15:17:20 2013 -0400
+++ b/src/wimax/model/simple-ofdm-wimax-phy.cc	Wed May 15 15:47:58 2013 -0400
@@ -241,6 +241,7 @@
 SimpleOfdmWimaxPhy::Send (SendParams *params)
 {
   OfdmSendParams *o_params = dynamic_cast<OfdmSendParams*> (params);
+  NS_ASSERT (o_params !=0);
   Send (o_params->GetBurst (),
         (WimaxPhy::ModulationType) o_params->GetModulationType (),
         o_params->GetDirection ());
@@ -284,6 +285,7 @@
     }
 
   SimpleOfdmWimaxChannel *channel = dynamic_cast<SimpleOfdmWimaxChannel*> (PeekPointer (GetChannel ()));
+  NS_ASSERT (channel != 0);
 
   if (m_nrRemainingBlocksToSend==1)
     {