summaryrefslogtreecommitdiff
path: root/svtools
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2015-01-27 16:43:22 +0100
committerStephan Bergmann <sbergman@redhat.com>2015-01-27 16:47:58 +0100
commit7d7c7c44e52814acdad39c6e92e53fd332c1e683 (patch)
treedfd3e3ca5896ae2d72cf23a2ee30713bcbcd56f4 /svtools
parent911f3a122a6adc36ac25940b29627b26405e2379 (diff)
UBSan-detected overflow when nWidthPixel is LONG_MAX and rCurrentZoom is 1
...from the call to SetColumnWidth( nId, LONG_MAX ); in BrowseBox::AutoSizeLastColumn(), e.g. happens when opening the Gallery in Draw. Change-Id: I151ae557d9d2bec52ecb0bd92b870fb0b91d7242
Diffstat (limited to 'svtools')
-rw-r--r--svtools/source/brwbox/datwin.cxx21
1 files changed, 15 insertions, 6 deletions
diff --git a/svtools/source/brwbox/datwin.cxx b/svtools/source/brwbox/datwin.cxx
index a3dd14049979..e56ef6b70de6 100644
--- a/svtools/source/brwbox/datwin.cxx
+++ b/svtools/source/brwbox/datwin.cxx
@@ -124,12 +124,21 @@ BrowserColumn::~BrowserColumn()
void BrowserColumn::SetWidth(sal_uLong nNewWidthPixel, const Fraction& rCurrentZoom)
{
_nWidth = nNewWidthPixel;
- double n = (double)_nWidth;
- n *= (double)rCurrentZoom.GetDenominator();
- if (!rCurrentZoom.GetNumerator())
- throw o3tl::divide_by_zero();
- n /= (double)rCurrentZoom.GetNumerator();
- _nOriginalWidth = n>0 ? (long)(n+0.5) : -(long)(-n+0.5);
+ // Avoid overflow when called with LONG_MAX from
+ // BrowseBox::AutoSizeLastColumn:
+ if (_nWidth == LONG_MAX)
+ {
+ _nOriginalWidth = _nWidth;
+ }
+ else
+ {
+ double n = (double)_nWidth;
+ n *= (double)rCurrentZoom.GetDenominator();
+ if (!rCurrentZoom.GetNumerator())
+ throw o3tl::divide_by_zero();
+ n /= (double)rCurrentZoom.GetNumerator();
+ _nOriginalWidth = n>0 ? (long)(n+0.5) : -(long)(-n+0.5);
+ }
}
void BrowserColumn::Draw( BrowseBox& rBox, OutputDevice& rDev, const Point& rPos, bool bCurs )