From c1be785be709db958aab47aec498dd45caf72eda Mon Sep 17 00:00:00 2001 From: Michael Carlberg Date: Sat, 29 Oct 2016 19:37:49 +0200 Subject: [PATCH] fix(progressbar): Add safety check Fixes jaagr/lemonbuddy#132 --- include/drawtypes/progressbar.hpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/include/drawtypes/progressbar.hpp b/include/drawtypes/progressbar.hpp index 1f99d1e8..5d3e25ab 100644 --- a/include/drawtypes/progressbar.hpp +++ b/include/drawtypes/progressbar.hpp @@ -78,13 +78,14 @@ namespace drawtypes { } else if (m_gradient) { size_t color = 0; for (size_t i = 0; i < fill_width; i++) { - if (i % m_colorstep == 0) + if (i % m_colorstep == 0 && color < m_colors.size()) m_fill->m_foreground = m_colors[color++]; m_builder->node(m_fill); } } else { size_t color = math_util::percentage_to_value(perc, m_colors.size() - 1); - m_fill->m_foreground = m_colors[color]; + if (color < m_colors.size()) + m_fill->m_foreground = m_colors[color]; for (size_t i = 0; i < fill_width; i++) { m_builder->node(m_fill); }