diff options
author | Andrew Price <anprice@redhat.com> | 2013-11-06 16:11:18 +0000 |
---|---|---|
committer | Andrew Price <anprice@redhat.com> | 2013-11-06 16:28:58 +0000 |
commit | 50392c7ff8deede0f3500e99d1d2d401c34af21b (patch) | |
tree | 4bc37694154163fd06c8c4513e26c62197be8a8b | |
parent | 20498553106d146be743e07b6f65cd512be10c9e (diff) | |
download | iowatcher-50392c7ff8deede0f3500e99d1d2d401c34af21b.tar.gz |
Add bounds checking in find_step
Check the value of cur_mini_step is sane before using it as an index to
mini_step array.
Signed-off-by: Andrew Price <anprice@redhat.com>
-rw-r--r-- | plot.c | 8 |
1 files changed, 5 insertions, 3 deletions
@@ -530,10 +530,12 @@ static double find_step(double first, double last, int num_ticks) /* Round to power of 10 */ step = exp(floor(log(step) / log10) * log10); /* Scale down step to provide enough ticks */ - while ((last - first) / (step * mini_step[cur_mini_step]) > num_ticks - && cur_mini_step < TICK_MINI_STEPS) + while (cur_mini_step < TICK_MINI_STEPS + && (last - first) / (step * mini_step[cur_mini_step]) > num_ticks) cur_mini_step++; - step *= mini_step[cur_mini_step - 1]; + + if (cur_mini_step > 0) + step *= mini_step[cur_mini_step - 1]; return step; } |