lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] master 7db5df5 1/4: Assert an implicit invariant


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 7db5df5 1/4: Assert an implicit invariant
Date: Mon, 19 Mar 2018 16:43:02 -0400 (EDT)

branch: master
commit 7db5df5016eb63a8dd7096efe416d4cffa3af2cd
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>

    Assert an implicit invariant
    
    Added this assertion:
        LMI_ASSERT(0 < excess);
    because without it, this line:
        int const r = 3 * (1 + (excess - 1) / 3);
    would be incorrect--e.g., if 'excess' equals zero.
    
    The assertion is presumably superfluous today because of the early exit
    a few lines above, but an explicit assertion guards against future
    changes to that early-exit code.
---
 miscellany.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/miscellany.cpp b/miscellany.cpp
index 3c969c7..b4505aa 100644
--- a/miscellany.cpp
+++ b/miscellany.cpp
@@ -139,6 +139,7 @@ int scale_power(int max_power, double min_value, double 
max_value)
     int const chars_required  = 1 + static_cast<int>(std::log10(widest));
     int const chars_available = max_power;
     int const excess = chars_required - chars_available;
+    LMI_ASSERT(0 < excess);
     int const r = 3 * (1 + (excess - 1) / 3);
 
     LMI_ASSERT(0 <= r);



reply via email to

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