Ensure that impossibly latency values do not affect stats
authorHamish Coleman <hamish@zot.org>
Fri, 17 Feb 2017 05:02:21 +0000 (13:02 +0800)
committerHamish Coleman <hamish@zot.org>
Fri, 17 Feb 2017 05:02:21 +0000 (13:02 +0800)
src/oping.c

index e439dbf..b4999c5 100644 (file)
@@ -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;