From 3885683edb804a976b89b95d8e5adf041e8912d7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Antoine=20Beaupr=C3=A9?= Date: Mon, 2 Dec 2013 22:32:46 -0500 Subject: [PATCH] cleanup safety checks make sure that if we go beyond the max ratio, we just mark it as one --- src/oping.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/oping.c b/src/oping.c index 14f5fd3..a630b8d 100644 --- a/src/oping.c +++ b/src/oping.c @@ -664,6 +664,9 @@ static int update_stats_from_context (ping_context_t *ctx, pingobj_iter_t *iter) int index = 0; ratio = latency / PING_DEF_TTL; + if (ratio > 1) { + ratio = 1; + } if (ratio > 2/3.0) { color = OPING_RED_HIST; } @@ -674,9 +677,12 @@ static int update_stats_from_context (ping_context_t *ctx, pingobj_iter_t *iter) /* HOST_PRINTF ("%%r%f-ia%d-", ratio, index); */ index = index % (BARS_LEN-1); /* HOST_PRINTF ("im%d-", index); */ - if (index < 0 || index >= BARS_LEN) { + if (index < 0) { index = 0; /* safety check */ } + if (index >= BARS_LEN) { + index = BARS_LEN -1; /* safety check */ + } wattron (ctx->window, COLOR_PAIR(color)); mvwprintw (ctx->window, /* y = */ 3, -- 2.30.2