Avoid equality comparison of doubles without accounting for error. Closes #350. Fixes #472

This commit is contained in:
dmiller 2016-10-16 04:48:53 +00:00
parent 9c8a435bbf
commit c1042454a9
2 changed files with 7 additions and 1 deletions

View file

@ -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]

View file

@ -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<double>::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)