From 6f18ec06d5d19173b77a1875bbd6dcc6982005e2 Mon Sep 17 00:00:00 2001 From: Albrecht Schlosser Date: Tue, 8 Mar 2016 13:40:18 +0000 Subject: [PATCH] Fix overflow in Fl_Valuator::precision(int) to 0...9 (STR #3280). git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@11315 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- CHANGES | 1 + src/Fl_Valuator.cxx | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/CHANGES b/CHANGES index 4c9fd31ff..cbdaeeb8a 100644 --- a/CHANGES +++ b/CHANGES @@ -164,6 +164,7 @@ CHANGES IN FLTK 1.3.4 RELEASED: ??? ?? 2016 (STR #3143). - Fixed a regression: restore the possibility to call fl_draw_image(buf,X,Y,W,H,D,L) with negative D and/or L arguments. + - Fixed overflow in Fl_Valuator::precision(int) to 0...9 (STR #3280). CHANGES IN FLTK 1.3.3 RELEASED: Nov 03 2014 diff --git a/src/Fl_Valuator.cxx b/src/Fl_Valuator.cxx index e086ae535..dcc3bf1b6 100644 --- a/src/Fl_Valuator.cxx +++ b/src/Fl_Valuator.cxx @@ -51,10 +51,19 @@ void Fl_Valuator::step(double s) { while (fabs(s-A/B) > epsilon && B<=(0x7fffffff/10)) {B *= 10; A = rint(s*B);} } -/** Sets the step value to 1/10digits.*/ -void Fl_Valuator::precision(int p) { +/** Sets the step value to 1.0 / 10digits. + + Precision \p digits is limited to 0...9 to avoid internal overflow errors. + Values outside this range are clamped. + + \note For negative values of \p digits the step value is set to + \p A = 1.0 and \p B = 1, i.e. 1.0/1 = 1. +*/ +void Fl_Valuator::precision(int digits) { + if (digits > 9) digits = 9; + else if (digits < 0) digits = 0; A = 1.0; - for (B = 1; p--;) B *= 10; + for (B = 1; digits--;) B *= 10; } /** Asks for partial redraw */ void Fl_Valuator::value_damage() {damage(FL_DAMAGE_EXPOSE);} // by default do partial-redraw