From: Florian Forster Date: Thu, 20 Nov 2014 13:35:53 +0000 (+0100) Subject: src/oping.c: Fix pretty ping graph movement. X-Git-Tag: liboping-1.8.0~2 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=4478fcf65e46d4d1746859187be5eab7df54e6e6;p=liboping.git src/oping.c: Fix pretty ping graph movement. Fixed the wrap-around case and adds support for windows larger than the history size. --- diff --git a/src/oping.c b/src/oping.c index a74cd42..debe237 100644 --- a/src/oping.c +++ b/src/oping.c @@ -979,12 +979,19 @@ static int update_graph_prettyping (ping_context_t *ctx, /* {{{ */ /* Determine the first index in the history we need to draw * the graph. */ history_offset = 0; - if (((size_t) x_max) < ctx->history_size) + if (((size_t) x_max) < ctx->history_size) /* window is smaller than history */ { if (ctx->history_index > x_max) history_offset = ctx->history_index - x_max; else /* wrap around */ - history_offset = ctx->history_index + x_max - ctx->history_size; + history_offset = ctx->history_index + ctx->history_size - x_max; + } + else /* window is larger than history */ + { + if (ctx->history_index != ctx->history_size) /* no longer growing. */ + history_offset = ctx->history_index; + else /* start-up */ + history_offset = 0; } for (x = 0; x < x_max; x++)