diff --git a/src/node/node-list.cc b/src/node/node-list.cc index 651be40b2..57e4dc07b 100644 --- a/src/node/node-list.cc +++ b/src/node/node-list.cc @@ -23,6 +23,7 @@ #include "ns3/object-vector.h" #include "ns3/config.h" #include "ns3/log.h" +#include "ns3/assert.h" #include "node-list.h" #include "node.h" @@ -140,6 +141,8 @@ NodeListPriv::GetNNodes (void) Ptr NodeListPriv::GetNode (uint32_t n) { + NS_ASSERT_MSG (n < m_nodes.size (), "Node index " << n << + " is out of range (only have " << m_nodes.size () << " nodes)."); return m_nodes[n]; } diff --git a/src/node/node.cc b/src/node/node.cc index 5469f1a44..c9040bcbf 100644 --- a/src/node/node.cc +++ b/src/node/node.cc @@ -27,6 +27,7 @@ #include "ns3/object-vector.h" #include "ns3/uinteger.h" #include "ns3/log.h" +#include "ns3/assert.h" NS_LOG_COMPONENT_DEFINE ("Node"); @@ -105,6 +106,8 @@ Node::AddDevice (Ptr device) Ptr Node::GetDevice (uint32_t index) const { + NS_ASSERT_MSG (n < m_devices.size (), "Device index " << n << + " is out of range (only have " << m_devices.size () << " devices)."); return m_devices[index]; } uint32_t @@ -124,6 +127,8 @@ Node::AddApplication (Ptr application) Ptr Node::GetApplication (uint32_t index) const { + NS_ASSERT_MSG (n < m_applications.size (), "Application index " << n << + " is out of range (only have " << m_applications.size () << " applications)."); return m_applications[index]; } uint32_t