Kaydet (Commit) d6fd4252 authored tarafından Eike Rathke's avatar Eike Rathke

Use invalid parameter error for malformed input, tdf#106956 follow-up

... instead of invalid procedure call.

Change-Id: I812f4c7041db9a116e65a24afb85164b4dd498b6
üst 2f3060d4
......@@ -2051,58 +2051,62 @@ RTLFUNC(CDateFromIso)
(void)pBasic;
(void)bWrite;
do
if ( rPar.Count() == 2 )
{
if ( rPar.Count() != 2 )
break;
OUString aStr = rPar.Get(1)->GetOUString();
const sal_Int32 nLen = aStr.getLength();
if (nLen != 8 && nLen != 10)
break;
OUString aYearStr, aMonthStr, aDayStr;
if (nLen == 8)
do
{
// YYYYMMDD
if (!comphelper::string::isdigitAsciiString(aStr))
OUString aStr = rPar.Get(1)->GetOUString();
const sal_Int32 nLen = aStr.getLength();
if (nLen != 8 && nLen != 10)
break;
aYearStr = aStr.copy( 0, 4 );
aMonthStr = aStr.copy( 4, 2 );
aDayStr = aStr.copy( 6, 2 );
}
else
{
// YYYY-MM-DD
const sal_Int32 nSep1 = aStr.indexOf('-');
if (nSep1 != 4)
break;
const sal_Int32 nSep2 = aStr.indexOf('-', nSep1+1);
if (nSep2 != 7)
break;
OUString aYearStr, aMonthStr, aDayStr;
if (nLen == 8)
{
// YYYYMMDD
if (!comphelper::string::isdigitAsciiString(aStr))
break;
aYearStr = aStr.copy( 0, 4 );
aMonthStr = aStr.copy( 5, 2 );
aDayStr = aStr.copy( 8, 2 );
if ( !comphelper::string::isdigitAsciiString(aYearStr) ||
!comphelper::string::isdigitAsciiString(aMonthStr) ||
!comphelper::string::isdigitAsciiString(aDayStr))
aYearStr = aStr.copy( 0, 4 );
aMonthStr = aStr.copy( 4, 2 );
aDayStr = aStr.copy( 6, 2 );
}
else
{
// YYYY-MM-DD
const sal_Int32 nSep1 = aStr.indexOf('-');
if (nSep1 != 4)
break;
const sal_Int32 nSep2 = aStr.indexOf('-', nSep1+1);
if (nSep2 != 7)
break;
aYearStr = aStr.copy( 0, 4 );
aMonthStr = aStr.copy( 5, 2 );
aDayStr = aStr.copy( 8, 2 );
if ( !comphelper::string::isdigitAsciiString(aYearStr) ||
!comphelper::string::isdigitAsciiString(aMonthStr) ||
!comphelper::string::isdigitAsciiString(aDayStr))
break;
}
double dDate;
if (!implDateSerial( (sal_Int16)aYearStr.toInt32(),
(sal_Int16)aMonthStr.toInt32(), (sal_Int16)aDayStr.toInt32(), dDate ))
break;
}
double dDate;
if (!implDateSerial( (sal_Int16)aYearStr.toInt32(),
(sal_Int16)aMonthStr.toInt32(), (sal_Int16)aDayStr.toInt32(), dDate ))
break;
rPar.Get(0)->PutDate( dDate );
rPar.Get(0)->PutDate( dDate );
return;
}
while (false);
return;
SbxBase::SetError( ERRCODE_SBX_BAD_PARAMETER );
}
else
{
StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
}
while (false);
StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
}
RTLFUNC(DateSerial)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment