From 7f9d14aa516527f6abf77b4df294acfa832d0dc6 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Sun, 21 Dec 2014 13:49:25 +0000 Subject: overlay: Negative modulus Don't use a negative index into the array if the desired element is negative, just wrap around properly into the ring for the chart. Signed-off-by: Chris Wilson --- overlay/chart.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'overlay') diff --git a/overlay/chart.c b/overlay/chart.c index 2a33d612..734e911f 100644 --- a/overlay/chart.c +++ b/overlay/chart.c @@ -143,7 +143,11 @@ static double value_at(struct chart *chart, int n) else if (n >= chart->current_sample) n = chart->current_sample - 1; - return chart->samples[n % chart->num_samples]; + n %= chart->num_samples; + if (n < 0) + n += chart->num_samples; + + return chart->samples[n]; } static double gradient_at(struct chart *chart, int n) -- cgit v1.2.3