[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master a049a0d 3/8: Forestall latent off-by-one erro
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master a049a0d 3/8: Forestall latent off-by-one errors |
Date: |
Wed, 12 Sep 2018 12:08:05 -0400 (EDT) |
branch: master
commit a049a0df6afeb52281ce00ce8ab44fe8b194865c
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>
Forestall latent off-by-one errors
In the section changed, 'year' was in index origin one, but everywhere
else it is in origin zero. Thus, in a loop over 'year', the counter
was asserted to lie within (0, size()] , and C++ arrays were actually
indexed by 'year-1'. It did do the right thing, but a consistent index
origin makes the revised version easier to understand and maintain.
---
ledger_pdf_generator_wx.cpp | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/ledger_pdf_generator_wx.cpp b/ledger_pdf_generator_wx.cpp
index e8d9c58..a5ba038 100644
--- a/ledger_pdf_generator_wx.cpp
+++ b/ledger_pdf_generator_wx.cpp
@@ -1422,14 +1422,15 @@ class numeric_summary_table_cell
int const year_max =
pdf_context_for_html_output.ledger().GetMaxLength();
int const age_last = 70;
std::array<int, 4> const summary_years =
- {{5, 10, 20, age_last - bourn_cast<int>(invar.Age)}
+ // "- 1": 70 (e.g.) is end-of-year age.
+ {{4, 9, 19, age_last - bourn_cast<int>(invar.Age) - 1}
};
for(auto const& year : summary_years)
{
// Skip row if it doesn't exist. For instance, if the issue
// age is 85 and the contract remains in force until age 100,
// then there is no twentieth duration and no age-70 row.
- if(!(0 < year && year <= year_max))
+ if(!(0 <= year && year < year_max))
{
continue;
}
@@ -1485,7 +1486,7 @@ class numeric_summary_table_cell
{
output_value = interpolate_html.evaluate
(columns[j].variable_name
- ,year - 1
+ ,year
);
}
- [lmi-commits] [lmi] master updated (d8aa128 -> 7bf948b), Greg Chicares, 2018/09/12
- [lmi-commits] [lmi] master 039924c 6/8: Refactor to prepare for a larger refactoring, Greg Chicares, 2018/09/12
- [lmi-commits] [lmi] master ff118b3 5/8: Assert that a refactoring will be safe, Greg Chicares, 2018/09/12
- [lmi-commits] [lmi] master 7bf948b 8/8: Refactor for clarity, Greg Chicares, 2018/09/12
- [lmi-commits] [lmi] master 0d7d4d5 4/8: Simplify some special-case logic to make it easier to relocate, Greg Chicares, 2018/09/12
- [lmi-commits] [lmi] master 99930af 1/8: Declare a variable only in the scope where it's used, Greg Chicares, 2018/09/12
- [lmi-commits] [lmi] master 039c1fd 2/8: Declare a variable only in the scope where it's used, Greg Chicares, 2018/09/12
- [lmi-commits] [lmi] master a049a0d 3/8: Forestall latent off-by-one errors,
Greg Chicares <=
- [lmi-commits] [lmi] master 1445c8d 7/8: Merge two identical blocks into a single function, Greg Chicares, 2018/09/12