From: Hamish Coleman Date: Fri, 17 Feb 2017 05:02:21 +0000 (+0800) Subject: Ensure that impossibly latency values do not affect stats X-Git-Url: https://git.octo.it/?p=liboping.git;a=commitdiff_plain;h=8291dce0cd5f40fc849c0c492a42605ccd9246f8 Ensure that impossibly latency values do not affect stats --- 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;