Avoid -fsanitize=signed-integer-overflow

Both Writer: "Table - Insert Table... - Insert", "Table - AutoFormat Styles...";
and Calc: select multiple cells, "Format - AutoFormat Styles..." cause

> svx/source/dialog/framelinkarray.cxx:82:29: runtime error: signed integer overflow: -4702111234474983744 + -4702111234474983746 cannot be represented in type 'long'
>     #0 0x7f84ef0e36ba in svx::frame::lclRecalcCoordVec(std::__debug::vector<long, std::allocator<long> >&, std::__debug::vector<long, std::allocator<long> > const&) svx/source/dialog/framelinkarray.cxx:82:29
>     #1 0x7f84ef0e780e in svx::frame::ArrayImpl::GetColPosition(unsigned long) const svx/source/dialog/framelinkarray.cxx:265:9
>     #2 0x7f84ef0f95ae in svx::frame::Array::GetColPosition(unsigned long) const svx/source/dialog/framelinkarray.cxx:762:20
>     #3 0x7f84ef0f9e56 in svx::frame::Array::GetWidth() const svx/source/dialog/framelinkarray.cxx:787:12
>     #4 0x7f852e9df8fd in ScAutoFmtPreview::CalcCellArray(bool) sc/source/ui/miscdlgs/autofmt.cxx:429:32
>     #5 0x7f852e9c7740 in ScAutoFmtPreview::Init() sc/source/ui/miscdlgs/autofmt.cxx:407:5
>     #6 0x7f852e9c9102 in ScAutoFmtPreview::ScAutoFmtPreview(vcl::Window*) sc/source/ui/miscdlgs/autofmt.cxx:73:5

where -4702111234474983746 = 0xbebebebebebebebe is ASan's uninitialized value
stored into ScAutoFmtPreview::mnLableColWidth et al.  Those (overflowing, even)
computations on uninitialized values appear to be harmless in practice, though,
presumably because they are overwritten with "real" values soon after.

Change-Id: I487fc4681afe79c4e8532595226cba4c9c0c9b2d
This commit is contained in:
Stephan Bergmann
2016-11-17 14:32:07 +01:00
parent 447a65db6b
commit 2f976709bc
2 changed files with 8 additions and 0 deletions

View File

@@ -404,6 +404,10 @@ void ScAutoFmtPreview::Init()
SetBorderStyle( WindowBorderStyle::MONO );
maArray.Initialize( 5, 5 );
maArray.SetUseDiagDoubleClipping( false );
mnLabelColWidth = 0;
mnDataColWidth1 = 0;
mnDataColWidth2 = 0;
mnRowHeight = 0;
CalcCellArray( false );
CalcLineMap();
}

View File

@@ -825,6 +825,10 @@ void AutoFormatPreview::Init()
SetBorderStyle( GetBorderStyle() | WindowBorderStyle::MONO );
maArray.Initialize( 5, 5 );
maArray.SetUseDiagDoubleClipping( false );
nLabelColWidth = 0;
nDataColWidth1 = 0;
nDataColWidth2 = 0;
nRowHeight = 0;
CalcCellArray( false );
CalcLineMap();
}