Skip to content

Commit

Permalink
GUI2: prevented Scrollbar (and by extension Slider) step size from be…
Browse files Browse the repository at this point in the history
…ing set to 0

This can potentially cause division-by-0 crashes.
  • Loading branch information
Vultraz committed Aug 20, 2017
1 parent ea15d45 commit 971de6f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/gui/widgets/scrollbar.hpp
Expand Up @@ -162,6 +162,11 @@ class scrollbar_base : public styled_widget

void set_step_size(const unsigned step_size)
{
// Step size can't be 0!
if(step_size == 0) {
throw std::invalid_argument("GUI2: scrollbar step size cannot be 0");
}

step_size_ = step_size;
recalculate();
}
Expand Down
2 changes: 1 addition & 1 deletion src/gui/widgets/slider.cpp
Expand Up @@ -468,7 +468,7 @@ builder_slider::builder_slider(const config& cfg)
, best_slider_length_(cfg["best_slider_length"])
, minimum_value_(cfg["minimum_value"])
, maximum_value_(cfg["maximum_value"])
, step_size_(cfg["step_size"])
, step_size_(cfg["step_size"].to_unsigned(1))
, value_(cfg["value"])
, minimum_value_label_(cfg["minimum_value_label"].t_str())
, maximum_value_label_(cfg["maximum_value_label"].t_str())
Expand Down

0 comments on commit 971de6f

Please sign in to comment.