Add bounds checking asserts to Node::GetApplication, NodeList::GetNode, and Node::GetDevice.

This commit is contained in:
Gustavo J. A. M. Carneiro committed 2008-08-06 16:06:44 +01:00
1 parent 5d1ac97ab0
commit b8b4889c57
2 files changed
+8

No files matched your search

+3
View File
@@ -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<Node>
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];
}
+5
View File
@@ -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<NetDevice> device)
Ptr<NetDevice>
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> application)
Ptr<Application>
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