lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] master 0e48166 1/3: Avoid guessing initial values


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 0e48166 1/3: Avoid guessing initial values
Date: Wed, 12 Sep 2018 04:05:08 -0400 (EDT)

branch: master
commit 0e48166af9998a0daa8c7e1feb7cd625716f942a
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>

    Avoid guessing initial values
    
    When a member ought to be initialized (e.g., here, where all members are
    handled in the ctor-initializer), but its value cannot be determined at
    the point of initialization, prefer '{}' to guessing a value.
    
    This former initial value has the dubious rationale that variables with
    similar names might have the same value:
    -    ,lines_on_last_page_ {lines_on_full_page_}
    and this one had been set explicitly in an early-exit conditional that
    has been removed:
    -    ,page_count_         {1}
    
    An alternative idea, not used here because it would be overkill, would
    be to choose a deliberately implausible value as a "canary", e.g.,
        ,page_count_         {INT_MIN}
    and, at exit, assert as a postcondition that the actual value is in a
    plausible range that excludes that initial value.
---
 report_table.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/report_table.cpp b/report_table.cpp
index 0317507..9a8e76e 100644
--- a/report_table.cpp
+++ b/report_table.cpp
@@ -195,8 +195,8 @@ paginator::paginator(int total_rows, int rows_per_group, 
int max_lines_per_page)
     ,rows_per_page_      {rows_per_group_ * groups_per_page_}
     // "-1 +": no blank-line separator after the last group.
     ,lines_on_full_page_ {-1 + lines_per_group_ * groups_per_page_}
-    ,lines_on_last_page_ {lines_on_full_page_}
-    ,page_count_         {1}
+    ,lines_on_last_page_ {}
+    ,page_count_         {}
 {
     LMI_ASSERT(0 <= total_rows);
     LMI_ASSERT(0 <  rows_per_group                      );



reply via email to

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