diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2016-06-20 09:54:14 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2016-06-20 09:54:14 +0200 |
commit | 2606915f0f480af30367a5d0f67adbf930c2c6b9 (patch) | |
tree | 9a992c95ac160b0c7ccba940eb8ae7714c6ff1b6 | |
parent | 8f56d408729108ed1c6fdca258d3ef6029863c78 (diff) |
Avoid undefined behavior when converting from double to sal_Int16
Change-Id: Iced9d25a15f25076b1c23b064eabfe5f0899882c
-rw-r--r-- | sc/source/core/tool/interpr2.cxx | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/sc/source/core/tool/interpr2.cxx b/sc/source/core/tool/interpr2.cxx index 812c858dcd7f..c9a73d47853f 100644 --- a/sc/source/core/tool/interpr2.cxx +++ b/sc/source/core/tool/interpr2.cxx @@ -305,7 +305,14 @@ void ScInterpreter::ScEasterSunday() if ( MustHaveParamCount( GetByte(), 1 ) ) { sal_Int16 nDay, nMonth, nYear; - nYear = (sal_Int16) ::rtl::math::approxFloor( GetDouble() ); + double x = rtl::math::approxFloor( GetDouble() ); + if (x <= sal_Int32(SAL_MIN_INT16) - 1 + || x >= sal_Int32(SAL_MAX_INT16) + 1) + { + PushIllegalArgument(); + return; + } + nYear = static_cast<sal_Int16>(x); if ( nYear < 100 ) nYear = pFormatter->ExpandTwoDigitYear( nYear ); if (nYear < 1583 || nYear > 9956) |