From 970872c96f92e0891625ff9463bd5ef40c7a7e3a Mon Sep 17 00:00:00 2001 From: Jinhao Date: Sun, 7 Jan 2018 04:18:23 +0800 Subject: [PATCH] fix bug that integer overflow in progress widget --- source/gui/widgets/progress.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/source/gui/widgets/progress.cpp b/source/gui/widgets/progress.cpp index 2c498f7c..8a679c4c 100644 --- a/source/gui/widgets/progress.cpp +++ b/source/gui/widgets/progress.cpp @@ -1,6 +1,6 @@ /* * A Progress Indicator Implementation - * Copyright(C) 2003-2017 Jinhao(cnjinhao@hotmail.com) + * Copyright(C) 2003-2018 Jinhao(cnjinhao@hotmail.com) * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at @@ -96,7 +96,11 @@ namespace nana { if (widget_) { - auto value_px = (widget_->size().width - border_px * 2) * value_ / max_; + auto value_px = (widget_->size().width - border_px * 2); + + //avoid overflow + if (value_ < max_) + value_px = static_cast(value_px * (double(value_) / double(max_))); if (value_px != value_px_) {