diff options
author | Andrew Price <anprice@redhat.com> | 2013-11-06 16:11:18 +0000 |
---|---|---|
committer | Chris Mason <clm@fb.com> | 2014-09-24 12:02:08 -0700 |
commit | 173545a6275189f7947e4473cf4dae0de74e1639 (patch) | |
tree | 7b9ab6f64ccae5048f7d8a0ccf5dc4fd7aa9f144 | |
parent | 9d382df04ccc0f145e7f13a23757b3d0ba5a9524 (diff) | |
download | blktrace-173545a6275189f7947e4473cf4dae0de74e1639.tar.gz |
iowatcher: 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-- | iowatcher/plot.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/iowatcher/plot.c b/iowatcher/plot.c index 971a253..d486f29 100644 --- a/iowatcher/plot.c +++ b/iowatcher/plot.c @@ -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; } |