[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_);
if(interval_i.value_is_keyword)
{
std::fill
@@ -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.
- [lmi-commits] [lmi] master updated (d7c4f5d -> 5753253), Greg Chicares, 2017/02/23
- [lmi-commits] [lmi] master eff49eb 1/8: Assert more invariants, Greg Chicares, 2017/02/23
- [lmi-commits] [lmi] master 15f8d03 3/8: Assert all post-construction invariants in a single function, Greg Chicares, 2017/02/23
- [lmi-commits] [lmi] master 2f6ea66 6/8: Demonstrate a simplification opportunity, Greg Chicares, 2017/02/23
- [lmi-commits] [lmi] master 3dc9aee 2/8: Refactor to prepare for improvements, Greg Chicares, 2017/02/23
- [lmi-commits] [lmi] master 3a73c40 4/8: Protect known (temporary) weak points with assertions,
Greg Chicares <=
- [lmi-commits] [lmi] master 5753253 8/8: Simplify realize_intervals(), Greg Chicares, 2017/02/23
- [lmi-commits] [lmi] master 132e2ac 7/8: Simplify: only one ctor needs to call realize_intervals(), Greg Chicares, 2017/02/23
- [lmi-commits] [lmi] master 1cfefc0 5/8: Assert post-construction invariants at end of each ctor, Greg Chicares, 2017/02/23