Commit df9b45a6 authored by Eli Fidler's avatar Eli Fidler

avoid division by zero, which is undefined behavior

UBSAN gave:
runtime error: division by zero
parent 760ea431
...@@ -439,11 +439,9 @@ TEST(Writer, InvalidEventSequence) { ...@@ -439,11 +439,9 @@ TEST(Writer, InvalidEventSequence) {
} }
} }
extern double zero; // clang -Wmissing-variable-declarations
double zero = 0.0; // Use global variable to prevent compiler warning
TEST(Writer, NaN) { TEST(Writer, NaN) {
double nan = zero / zero; double nan = std::numeric_limits<double>::quiet_NaN();
EXPECT_TRUE(internal::Double(nan).IsNan()); EXPECT_TRUE(internal::Double(nan).IsNan());
StringBuffer buffer; StringBuffer buffer;
{ {
...@@ -461,7 +459,8 @@ TEST(Writer, NaN) { ...@@ -461,7 +459,8 @@ TEST(Writer, NaN) {
} }
TEST(Writer, Inf) { TEST(Writer, Inf) {
double inf = 1.0 / zero; double inf = std::numeric_limits<double>::infinity();
EXPECT_TRUE(internal::Double(inf).IsInf()); EXPECT_TRUE(internal::Double(inf).IsInf());
StringBuffer buffer; StringBuffer buffer;
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment