From c1042454a956552d8311270c28ef05b0bc380bf2 Mon Sep 17 00:00:00 2001 From: dmiller Date: Sun, 16 Oct 2016 04:48:53 +0000 Subject: [PATCH] Avoid equality comparison of doubles without accounting for error. Closes #350. Fixes #472 --- CHANGELOG | 6 ++++++ timing.cc | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 98e62e693..4950934b6 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,11 @@ # Nmap Changelog ($Id$); -*-text-*- +o [GH#350] Fix an assertion failure due to floating point error in equality + comparison, which triggered mainly on OpenBSD: + assertion "diff <= interval" failed: file "timing.cc", line 440 + This was reported earlier as [GH#472] but the assertion fixed there was a + different one. [David Carlier] + o [Nping][GH#559] Fix Nping's ability to use Npcap on Windows. A privilege check was performed too late, so the Npcap loading code assumed the user had no rights. [Yang Luo, Daniel Miller] diff --git a/timing.cc b/timing.cc index 1c1be23ed..60a6a4086 100644 --- a/timing.cc +++ b/timing.cc @@ -437,7 +437,7 @@ void RateMeter::update(double amount, const struct timeval *now) { interval = MAX(current_rate_history, diff); else interval = TIMEVAL_SUBTRACT(*now, start_tv) / 1000000.0; - assert(diff <= interval); + assert(diff <= interval + std::numeric_limits::epsilon()); /* If we record an amount in the very same instant that the timer is started, there's no way to calculate meaningful rates. Ignore it. */ if (interval == 0.0)