From: Florian Forster Date: Sun, 12 Oct 2014 15:32:06 +0000 (+0200) Subject: src/oping.c: Make sure the reported percentile value doesn't exceed the maximum. X-Git-Tag: liboping-1.8.0~10 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=4834a347c0d674ff7a03768ead08dd02b5590c5f;p=liboping.git src/oping.c: Make sure the reported percentile value doesn't exceed the maximum. --- diff --git a/src/oping.c b/src/oping.c index 6496331..5e63392 100644 --- a/src/oping.c +++ b/src/oping.c @@ -278,6 +278,7 @@ static double context_get_percentile (ping_context_t *ctx, /* {{{ */ double threshold = percentile / 100.0; double index_to_ms_factor; size_t i; + double ret; if (ctx->histogram_ratio == NULL) return (NAN); @@ -295,7 +296,13 @@ static double context_get_percentile (ping_context_t *ctx, /* {{{ */ /* Multiply with i+1, because we're interested in the _upper_ bound of * each bucket. */ - return (index_to_ms_factor * ((double) (i + 1))); + ret = (index_to_ms_factor * ((double) (i + 1))); + + /* Avoid reporting a higher latency than latency_max. */ + if (ret > ctx->latency_max) + ret = ctx->latency_max; + + return (ret); } /* }}} double context_get_percentile */ static double context_get_stddev (ping_context_t *ctx) /* {{{ */