[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 04cc85e 1/2: Try to provoke division by zero
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 04cc85e 1/2: Try to provoke division by zero in round_to ctor-initializer |
Date: |
Fri, 7 Sep 2018 11:32:39 -0400 (EDT) |
branch: master
commit 04cc85ef1b2b217ccdd5cc3997ec79e018f0fbbc
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>
Try to provoke division by zero in round_to ctor-initializer
Added a test to guard this ctor against the problem discussed in the
last several commits for class paginator. It seems unlikely that 10^N
will equal zero for any finite negative integer N.
---
round_to_test.cpp | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/round_to_test.cpp b/round_to_test.cpp
index 4b5b62a..a14c631 100644
--- a/round_to_test.cpp
+++ b/round_to_test.cpp
@@ -28,6 +28,7 @@
#include "test_tools.hpp"
#include <algorithm> // max()
+#include <climits> // INT_MIN
#include <ios>
#include <iostream>
#include <ostream>
@@ -543,6 +544,16 @@ int test_main(int, char*[])
BOOST_TEST(2 == round1.decimals());
BOOST_TEST(r_to_nearest == round1.style());
+ // Try to provoke division by zero in ctor-initializer.
+ //
+ // nonstd::power() negates a negative exponent, but negating
+ // INT_MIN constitutes UB, so use 1 + INT_MIN.
+ BOOST_TEST_THROW
+ (round_to<double>(1 + INT_MIN, r_to_nearest)
+ ,std::domain_error
+ ,"Invalid number of decimals."
+ );
+
// The software default rounding style and the hardware rounding
// mode may be either synchronized or not, so test both ways.
std::cout << " Default style synchronized to hardware mode:\n";