diff options
author | Andreas Heinisch <andreas.heinisch@yahoo.de> | 2020-03-24 12:16:35 +0100 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2020-03-27 14:16:03 +0100 |
commit | 384afeaa3df919585d9df1df5b4cf6c93536e319 (patch) | |
tree | ef0d75a81bc4ef7e4dbfdefb95c6273e9d3fab88 /basic/source/comp | |
parent | 98b07a9858ee285665125ccd126a46376017f0b4 (diff) |
tdf#130476 - take into account trailing data type characters
For hex/octal literals take into account trailing suffix types
from GetSuffixType in basic/source/comp/scanner.cxx.
The suffix type $ (String) is not allowed for numeric values
or hex/octal literals and leads to a syntax error
(ERRCODE_BASIC_SYNTAX) during compile time.
Change-Id: Id6c4bbf1296361879f7dec461a48bbdc5c683338
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/90978
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'basic/source/comp')
-rw-r--r-- | basic/source/comp/scanner.cxx | 55 |
1 files changed, 46 insertions, 9 deletions
diff --git a/basic/source/comp/scanner.cxx b/basic/source/comp/scanner.cxx index 7c192b3a0107..5d93f5362510 100644 --- a/basic/source/comp/scanner.cxx +++ b/basic/source/comp/scanner.cxx @@ -433,6 +433,11 @@ bool SbiScanner::NextSym() ++nLineIdx; ++nCol; } + // tdf#130476 - don't allow String trailing data type character with numbers + if ( t == SbxSTRING ) + { + GenError( ERRCODE_BASIC_SYNTAX ); + } } } @@ -482,17 +487,49 @@ bool SbiScanner::NextSym() GenError( ERRCODE_BASIC_BAD_CHAR_IN_NUMBER ); } } - if(nCol < aLine.getLength() && aLine[nCol] == '&') + + // tdf#130476 - take into account trailing data type characters + if( nCol < aLine.getLength() ) { - ++nLineIdx; - ++nCol; + SbxDataType t(GetSuffixType(aLine[nCol])); + if( t != SbxVARIANT ) + { + eScanType = t; + ++nLineIdx; + ++nCol; + } + // tdf#130476 - don't allow String trailing data type character with numbers + if ( t == SbxSTRING ) + { + GenError( ERRCODE_BASIC_SYNTAX ); + } + } + + // tdf#130476 - take into account trailing data type characters + switch ( eScanType ) + { + case SbxINTEGER: + nVal = static_cast<double>( static_cast<sal_Int16>(lu) ); + if ( lu > SbxMAXUINT ) + { + bOverflow = true; + } + break; + case SbxLONG: nVal = static_cast<double>( static_cast<sal_Int32>(lu) ); break; + case SbxVARIANT: + { + // tdf#62326 - If the value of the hex string without explicit type character lies within + // the range of 0x8000 (SbxMAXINT + 1) and 0xFFFF (SbxMAXUINT) inclusive, cast the value + // to 16 bit in order to get signed integers, e.g., SbxMININT through SbxMAXINT + sal_Int32 ls = (lu > SbxMAXINT && lu <= SbxMAXUINT) ? static_cast<sal_Int16>(lu) : static_cast<sal_Int32>(lu); + eScanType = ( ls >= SbxMININT && ls <= SbxMAXINT ) ? SbxINTEGER : SbxLONG; + nVal = static_cast<double>(ls); + break; + } + default: + nVal = static_cast<double>(lu); + break; } - // tdf#62326 - If the value of the hex string lies within the range of 0x8000 (SbxMAXINT + 1) - // and 0xFFFF (SbxMAXUINT) inclusive, cast the value to 16 bit in order to get - // signed integers, e.g., SbxMININT through SbxMAXINT - sal_Int32 ls = (lu > SbxMAXINT && lu <= SbxMAXUINT) ? static_cast<sal_Int16>(lu) : static_cast<sal_Int32>(lu); - nVal = static_cast<double>(ls); - eScanType = ( ls >= SbxMININT && ls <= SbxMAXINT ) ? SbxINTEGER : SbxLONG; if( bOverflow ) GenError( ERRCODE_BASIC_MATH_OVERFLOW ); } |