From bf762f52d6e66016371fa0871189acf348fc71ba Mon Sep 17 00:00:00 2001 From: Alexander Krotov Date: Fri, 7 Apr 2017 20:22:02 +0300 Subject: [PATCH] core: Check that CDF is not empty in EmpiricalRandomVariable::Validate () --- src/core/model/random-variable-stream.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/core/model/random-variable-stream.cc b/src/core/model/random-variable-stream.cc index 5fda2500b..dca094d0c 100644 --- a/src/core/model/random-variable-stream.cc +++ b/src/core/model/random-variable-stream.cc @@ -1575,13 +1575,9 @@ EmpiricalRandomVariable::GetValue (void) NS_LOG_FUNCTION (this); // Return a value from the empirical distribution // This code based (loosely) on code by Bruce Mah (Thanks Bruce!) - if (m_emp.size () == 0) - { - return 0.0; // HuH? No empirical data - } if (!m_validated) { - Validate (); // Insure in non-decreasing + Validate (); } // Get a uniform random variable in [0,1]. @@ -1640,6 +1636,10 @@ void EmpiricalRandomVariable::CDF (double v, double c) void EmpiricalRandomVariable::Validate () { NS_LOG_FUNCTION (this); + if (m_emp.empty ()) + { + NS_FATAL_ERROR ("CDF is not initialized"); + } ValueCDF prior = m_emp[0]; for (std::vector::size_type i = 0; i < m_emp.size (); ++i) {