[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [lmi] master 3a73c40 4/8: Protect known (temporary) weak p

From: Greg Chicares
Subject: [lmi-commits] [lmi] master 3a73c40 4/8: Protect known (temporary) weak points with assertions
Date: Thu, 23 Feb 2017 05:29:07 -0500 (EST)

branch: master
commit 3a73c40e117963643123187de2f62eb9628be211
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>

    Protect known (temporary) weak points with assertions
    Added assertions at the end of fill_interval_gaps(), which may produce
    improper intervals, at least for now; and in realize_intervals(), where
    such intervals might cause segfaults. Guarding these known weak points
    makes it safer to restructure invariant checks. It is easier to add a
    thousand assertions than to attempt to get a single backtrace with the
    debugging tools available for 'wine'.
 input_sequence.cpp | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/input_sequence.cpp b/input_sequence.cpp
index 30e51dd..36e42c1 100644
--- a/input_sequence.cpp
+++ b/input_sequence.cpp
@@ -316,6 +316,9 @@ void InputSequence::realize_intervals()
     for(auto const& interval_i : intervals_)
+        LMI_ASSERT(0 <= interval_i.begin_duration);
+        LMI_ASSERT(interval_i.begin_duration <= interval_i.end_duration);
+        LMI_ASSERT(interval_i.end_duration <= years_to_maturity_);
@@ -493,8 +496,9 @@ void assert_sane_and_ordered_partition
 /// The for-statement's second branch creates an improper interval if
 /// the parsed expression had overlapping intervals. Alternatively, it
 /// would create no such interval if its '!=' condition were replaced
-/// by '<'; it is not obvious which way is better. Either way, the
-/// anomaly is caught downstream.
+/// by '<'; it is not obvious which way is better. For now at least,
+/// assert_sane_and_ordered_partition() is called at the end of this
+/// function to trap the anomaly.
 void fill_interval_gaps
     (std::vector<ValueInterval> const& in
@@ -553,6 +557,10 @@ void fill_interval_gaps
     out.back().end_duration = years_to_maturity;
     out.back().end_mode     = e_maturity;
+    // This is necessary only to trap any improper interval that
+    // may have been inserted.
+    assert_sane_and_ordered_partition(out, years_to_maturity);
 } // Unnamed namespace.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]