From 8291dce0cd5f40fc849c0c492a42605ccd9246f8 Mon Sep 17 00:00:00 2001 From: Hamish Coleman Date: Fri, 17 Feb 2017 13:02:21 +0800 Subject: [PATCH] Ensure that impossibly latency values do not affect stats --- src/oping.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/oping.c b/src/oping.c index e439dbf..b4999c5 100644 --- a/src/oping.c +++ b/src/oping.c @@ -293,6 +293,11 @@ static void clean_history (ping_context_t *ctx) /* {{{ */ memcpy (ctx->history_by_value, ctx->history_by_time, sizeof (ctx->history_by_time)); + /* Remove impossible values */ + for (i = 0; i < ctx->history_size; i++) + if (ctx->history_by_value[i]<0) + ctx->history_by_value[i]=NAN; + /* Sort all RTTs. */ qsort (ctx->history_by_value, ctx->history_size, sizeof (ctx->history_by_value[0]), compare_double); @@ -1046,6 +1051,10 @@ static int update_graph_prettyping (ping_context_t *ctx, /* {{{ */ index = (history_offset + x) % ctx->history_size; latency = ctx->history_by_time[index]; + if (latency < 0) { + continue; + } + if (latency >= 0.0) { double ratio; -- 2.11.0