incubator-ooo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject svn commit: r1362886 - in /incubator/ooo/trunk/main/sc/source/filter: excel/ inc/ lotus/
Date Wed, 18 Jul 2012 11:26:13 GMT
Author: alg
Date: Wed Jul 18 11:26:13 2012
New Revision: 1362886

URL: http://svn.apache.org/viewvc?rev=1362886&view=rev
Log:
filter review Lotus WK
Patch by: Eike Rathke

Modified:
    incubator/ooo/trunk/main/sc/source/filter/excel/fontbuff.cxx
    incubator/ooo/trunk/main/sc/source/filter/excel/tokstack.cxx
    incubator/ooo/trunk/main/sc/source/filter/inc/lotfntbf.hxx
    incubator/ooo/trunk/main/sc/source/filter/inc/lotimpop.hxx
    incubator/ooo/trunk/main/sc/source/filter/inc/op.h
    incubator/ooo/trunk/main/sc/source/filter/inc/root.hxx
    incubator/ooo/trunk/main/sc/source/filter/inc/tokstack.hxx
    incubator/ooo/trunk/main/sc/source/filter/lotus/filter.cxx
    incubator/ooo/trunk/main/sc/source/filter/lotus/lotattr.cxx
    incubator/ooo/trunk/main/sc/source/filter/lotus/lotform.cxx
    incubator/ooo/trunk/main/sc/source/filter/lotus/lotimpop.cxx
    incubator/ooo/trunk/main/sc/source/filter/lotus/lotread.cxx
    incubator/ooo/trunk/main/sc/source/filter/lotus/memory.cxx
    incubator/ooo/trunk/main/sc/source/filter/lotus/op.cxx
    incubator/ooo/trunk/main/sc/source/filter/lotus/tool.cxx

Modified: incubator/ooo/trunk/main/sc/source/filter/excel/fontbuff.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sc/source/filter/excel/fontbuff.cxx?rev=1362886&r1=1362885&r2=1362886&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sc/source/filter/excel/fontbuff.cxx (original)
+++ incubator/ooo/trunk/main/sc/source/filter/excel/fontbuff.cxx Wed Jul 18 11:26:13 2012
@@ -44,8 +44,6 @@
 #include "patattr.hxx"
 #include "ftools.hxx"
 
-const sal_uInt16	LotusFontBuffer::nSize = 8;
-
 void LotusFontBuffer::Fill( const sal_uInt8 nIndex, SfxItemSet& rItemSet )
 {
 	sal_uInt8	nIntIndex = nIndex & 0x07;

Modified: incubator/ooo/trunk/main/sc/source/filter/excel/tokstack.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sc/source/filter/excel/tokstack.cxx?rev=1362886&r1=1362885&r2=1362886&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sc/source/filter/excel/tokstack.cxx (original)
+++ incubator/ooo/trunk/main/sc/source/filter/excel/tokstack.cxx Wed Jul 18 11:26:13 2012
@@ -118,42 +118,30 @@ TokenPool::TokenPool( void )
 
 TokenPool::~TokenPool()
 {
-	sal_uInt16	n;
+    sal_uInt16	n;
 
-	delete[] pP_Id;
-	delete[] pElement;
-	delete[] pType;
-	delete[] pSize;
-	delete[] pP_Dbl;
+    delete[] pP_Id;
+    delete[] pElement;
+    delete[] pType;
+    delete[] pSize;
+    delete[] pP_Dbl;
     delete[] pP_Err;
 
-	for( n = 0 ; n < nP_RefTr ; n++/*, pAktTr++*/ )
-	{
-		if( ppP_RefTr[ n ] )
-			delete ppP_RefTr[ n ];
-	}
-	delete[] ppP_RefTr;
-
-	for( n = 0 ; n < nP_Str ; n++/*, pAktStr++*/ )
-	{
-		if( ppP_Str[ n ] )
-			delete ppP_Str[ n ];
-	}
-	delete[] ppP_Str;
-
-	for( n = 0 ; n < nP_Ext ; n++ )
-	{
-		if( ppP_Ext[ n ] )
-			delete ppP_Ext[ n ];
-	}
-	delete[] ppP_Ext;
-
-	for( n = 0 ; n < nP_Nlf ; n++ )
-	{
-		if( ppP_Nlf[ n ] )
-			delete ppP_Nlf[ n ];
-	}
-	delete[] ppP_Nlf;
+    for( n = 0 ; n < nP_RefTr ; n++ )
+        delete ppP_RefTr[ n ];
+    delete[] ppP_RefTr;
+
+    for( n = 0 ; n < nP_Str ; n++ )
+        delete ppP_Str[ n ];
+    delete[] ppP_Str;
+
+    for( n = 0 ; n < nP_Ext ; n++ )
+        delete ppP_Ext[ n ];
+    delete[] ppP_Ext;
+
+    for( n = 0 ; n < nP_Nlf ; n++ )
+        delete ppP_Nlf[ n ];
+    delete[] ppP_Nlf;
 
     for( n = 0 ; n < nP_Matrix ; n++ )
     {
@@ -162,16 +150,38 @@ TokenPool::~TokenPool()
     }
     delete[] ppP_Matrix;
 
-	delete pScToken;
+    delete pScToken;
 }
 
 
-void TokenPool::GrowString( void )
+/** Returns the new number of elements, or 0 if overflow. */
+static sal_uInt16 lcl_canGrow( sal_uInt16 nOld, sal_uInt16 nByMin = 1 )
 {
-	sal_uInt16		nP_StrNew = nP_Str * 2;
+    if (!nOld)
+        return nByMin ? nByMin : 1;
+    if (nOld == SAL_MAX_UINT16)
+        return 0;
+    sal_uInt32 nNew = ::std::max( static_cast<sal_uInt32>(nOld) * 2, 
+            static_cast<sal_uInt32>(nOld) + nByMin);
+    if (nNew > SAL_MAX_UINT16)
+        nNew = SAL_MAX_UINT16;
+    if (nNew - nByMin < nOld)
+        nNew = 0;
+    return static_cast<sal_uInt16>(nNew);
+}
+
+
+bool TokenPool::GrowString( void )
+{
+    sal_uInt16 nP_StrNew = lcl_canGrow( nP_Str);
+    if (!nP_StrNew)
+        return false;
+
 	sal_uInt16		nL;
 
-	String**	ppP_StrNew = new String *[ nP_StrNew ];
+	String**	ppP_StrNew = new (::std::nothrow) String *[ nP_StrNew ];
+    if (!ppP_StrNew)
+        return false;
 
 	for( nL = 0 ; nL < nP_Str ; nL++ )
 		ppP_StrNew[ nL ] = ppP_Str[ nL ];
@@ -182,14 +192,20 @@ void TokenPool::GrowString( void )
 
 	delete[]	ppP_Str;
 	ppP_Str = ppP_StrNew;
+    return true;
 }
 
 
-void TokenPool::GrowDouble( void )
+bool TokenPool::GrowDouble( void )
 {
-	sal_uInt16		nP_DblNew = nP_Dbl * 2;
+    sal_uInt16 nP_DblNew = lcl_canGrow( nP_Dbl);
+    if (!nP_DblNew)
+        return false;
+
 
-	double*		pP_DblNew = new double[ nP_DblNew ];
+	double*		pP_DblNew = new (::std::nothrow) double[ nP_DblNew ];
+    if (!pP_DblNew)
+        return false;
 
 	for( sal_uInt16 nL = 0 ; nL < nP_Dbl ; nL++ )
 		pP_DblNew[ nL ] = pP_Dbl[ nL ];
@@ -198,31 +214,46 @@ void TokenPool::GrowDouble( void )
 
 	delete[] pP_Dbl;
 	pP_Dbl = pP_DblNew;
+    return true;
 }
 
 
-//UNUSED2009-05 void TokenPool::GrowError( void )
-//UNUSED2009-05 {
-//UNUSED2009-05     sal_uInt16      nP_ErrNew = nP_Err * 2;
-//UNUSED2009-05 
-//UNUSED2009-05     sal_uInt16*     pP_ErrNew = new sal_uInt16[ nP_ErrNew ];
-//UNUSED2009-05 
-//UNUSED2009-05     for( sal_uInt16 nL = 0 ; nL < nP_Err ; nL++ )
-//UNUSED2009-05         pP_ErrNew[ nL ] = pP_Err[ nL ];
-//UNUSED2009-05 
-//UNUSED2009-05     nP_Err = nP_ErrNew;
-//UNUSED2009-05 
-//UNUSED2009-05     delete[] pP_Err;
-//UNUSED2009-05     pP_Err = pP_ErrNew;
-//UNUSED2009-05 }
+/* TODO: in case we had FormulaTokenArray::AddError() */
+#if 0
+void TokenPool::GrowError( void )
+{
+    sal_uInt16 nP_ErrNew = lcl_canGrow( nP_Err);
+    if (!nP_ErrNew)
+        return false;
+
+
+    sal_uInt16*     pP_ErrNew = new (::std::nothrow) sal_uInt16[ nP_ErrNew ];
+    if (!pP_ErrNew)
+        return false;
 
+    for( sal_uInt16 nL = 0 ; nL < nP_Err ; nL++ )
+        pP_ErrNew[ nL ] = pP_Err[ nL ];
 
-void TokenPool::GrowTripel( void )
+    nP_Err = nP_ErrNew;
+
+    delete[] pP_Err;
+    pP_Err = pP_ErrNew;
+    return true;
+}
+#endif
+
+
+bool TokenPool::GrowTripel( sal_uInt16 nByMin )
 {
-	sal_uInt16			nP_RefTrNew = nP_RefTr * 2;
+    sal_uInt16 nP_RefTrNew = lcl_canGrow( nP_RefTr, nByMin);
+    if (!nP_RefTrNew)
+        return false;
+
 	sal_uInt16			nL;
 
-	ScSingleRefData**	ppP_RefTrNew = new ScSingleRefData *[ nP_RefTrNew ];
+	ScSingleRefData**	ppP_RefTrNew = new (::std::nothrow) ScSingleRefData *[ nP_RefTrNew ];
+    if (!ppP_RefTrNew)
+        return false;
 
 	for( nL = 0 ; nL < nP_RefTr ; nL++ )
 		ppP_RefTrNew[ nL ] = ppP_RefTr[ nL ];
@@ -233,14 +264,20 @@ void TokenPool::GrowTripel( void )
 
 	delete[] ppP_RefTr;
 	ppP_RefTr = ppP_RefTrNew;
+    return true;
 }
 
 
-void TokenPool::GrowId( void )
+bool TokenPool::GrowId( void )
 {
-	sal_uInt16	nP_IdNew = nP_Id * 2;
+    sal_uInt16 nP_IdNew = lcl_canGrow( nP_Id);
+    if (!nP_IdNew)
+        return false;
 
-	sal_uInt16*	pP_IdNew = new sal_uInt16[ nP_IdNew ];
+
+	sal_uInt16*	pP_IdNew = new (::std::nothrow) sal_uInt16[ nP_IdNew ];
+    if (!pP_IdNew)
+        return false;
 
 	for( sal_uInt16 nL = 0 ; nL < nP_Id ; nL++ )
 		pP_IdNew[ nL ] = pP_Id[ nL ];
@@ -249,16 +286,27 @@ void TokenPool::GrowId( void )
 
 	delete[] pP_Id;
 	pP_Id = pP_IdNew;
+    return true;
 }
 
 
-void TokenPool::GrowElement( void )
+bool TokenPool::GrowElement( void )
 {
-	sal_uInt16	nElementNew = nElement * 2;
+    sal_uInt16 nElementNew = lcl_canGrow( nElement);
+    if (!nElementNew)
+        return false;
+
 
-	sal_uInt16*	pElementNew = new sal_uInt16[ nElementNew ];
-	E_TYPE*	pTypeNew = new E_TYPE[ nElementNew ];
-	sal_uInt16*	pSizeNew = new sal_uInt16[ nElementNew ];
+	sal_uInt16*	pElementNew = new (::std::nothrow) sal_uInt16[ nElementNew ];
+	E_TYPE*	pTypeNew = new (::std::nothrow) E_TYPE[ nElementNew ];
+	sal_uInt16*	pSizeNew = new (::std::nothrow) sal_uInt16[ nElementNew ];
+    if (!pElementNew || !pTypeNew || !pSizeNew)
+    {
+        delete [] pElementNew;
+        delete [] pTypeNew;
+        delete [] pSizeNew;
+        return false;
+    }
 
 	for( sal_uInt16 nL = 0 ; nL < nElement ; nL++ )
 	{
@@ -275,14 +323,19 @@ void TokenPool::GrowElement( void )
 	pElement = pElementNew;
 	pType = pTypeNew;
 	pSize = pSizeNew;
+    return true;
 }
 
 
-void TokenPool::GrowExt( void )
+bool TokenPool::GrowExt( void )
 {
-	sal_uInt16		nNewSize = nP_Ext * 2;
+    sal_uInt16 nNewSize = lcl_canGrow( nP_Ext);
+    if (!nNewSize)
+        return false;
 
-	EXTCONT**	ppNew = new EXTCONT*[ nNewSize ];
+	EXTCONT**	ppNew = new (::std::nothrow) EXTCONT*[ nNewSize ];
+    if (!ppNew)
+        return false;
 
     memset( ppNew, 0, sizeof( EXTCONT* ) * nNewSize );
 	memcpy( ppNew, ppP_Ext, sizeof( EXTCONT* ) * nP_Ext );
@@ -290,14 +343,19 @@ void TokenPool::GrowExt( void )
 	delete[] ppP_Ext;
 	ppP_Ext = ppNew;
 	nP_Ext = nNewSize;
+    return true;
 }
 
 
-void TokenPool::GrowNlf( void )
+bool TokenPool::GrowNlf( void )
 {
-	sal_uInt16		nNewSize = nP_Nlf * 2;
+    sal_uInt16 nNewSize = lcl_canGrow( nP_Nlf);
+    if (!nNewSize)
+        return false;
 
-	NLFCONT**	ppNew = new NLFCONT*[ nNewSize ];
+	NLFCONT**	ppNew = new (::std::nothrow) NLFCONT*[ nNewSize ];
+    if (!ppNew)
+        return false;
 
     memset( ppNew, 0, sizeof( NLFCONT* ) * nNewSize );
 	memcpy( ppNew, ppP_Nlf, sizeof( NLFCONT* ) * nP_Nlf );
@@ -305,14 +363,19 @@ void TokenPool::GrowNlf( void )
 	delete[] ppP_Nlf;
     ppP_Nlf = ppNew;
 	nP_Nlf = nNewSize;
+    return true;
 }
 
 
-void TokenPool::GrowMatrix( void )
+bool TokenPool::GrowMatrix( void )
 {
-    sal_uInt16      nNewSize = nP_Matrix * 2;
+    sal_uInt16 nNewSize = lcl_canGrow( nP_Matrix);
+    if (!nNewSize)
+        return false;
 
-    ScMatrix**  ppNew = new ScMatrix*[ nNewSize ];
+    ScMatrix**  ppNew = new (::std::nothrow) ScMatrix*[ nNewSize ];
+    if (!ppNew)
+        return false;
 
     memset( ppNew, 0, sizeof( ScMatrix* ) * nNewSize );
     memcpy( ppNew, ppP_Matrix, sizeof( ScMatrix* ) * nP_Matrix );
@@ -320,230 +383,230 @@ void TokenPool::GrowMatrix( void )
     delete[] ppP_Matrix;
     ppP_Matrix = ppNew;
     nP_Matrix = nNewSize;
+    return true;
 }
 
-void TokenPool::GetElement( const sal_uInt16 nId )
+bool TokenPool::GetElement( const sal_uInt16 nId )
 {
-	DBG_ASSERT( nId < nElementAkt, "*TokenPool::GetElement(): Id zu gross!?" );
+	DBG_ASSERT( nId < nElementAkt, "*TokenPool::GetElement(): Id too large!?" );
+    if (nId >= nElementAkt)
+        return false;
 
+    bool bRet = true;
 	if( pType[ nId ] == T_Id )
-		GetElementRek( nId );
+		bRet = GetElementRek( nId );
 	else
 	{
 		switch( pType[ nId ] )
 		{
-#ifdef DBG_UTIL
-			case T_Id:
-				DBG_ERROR( "-TokenPool::GetElement(): hier hast Du nichts zu suchen!" );
-				break;
-#endif
 			case T_Str:
-				pScToken->AddString( ppP_Str[ pElement[ nId ] ]->GetBuffer() );
+                {
+                    sal_uInt16 n = pElement[ nId ];
+                    String* p = ( n < nP_Str )? ppP_Str[ n ] : NULL;
+                    if (p)
+                        pScToken->AddString( *p );
+                    else
+                        bRet = false;
+                }
 				break;
 			case T_D:
-				pScToken->AddDouble( pP_Dbl[ pElement[ nId ] ] );
+                {
+                    sal_uInt16 n = pElement[ nId ];
+                    if (n < nP_Dbl)
+                        pScToken->AddDouble( pP_Dbl[ n ] );
+                    else
+                        bRet = false;
+                }
 				break;
             case T_Err:
-#if 0   // erAck
-                pScToken->AddError( pP_Err[ pElement[ nId ] ] );
+/* TODO: in case we had FormulaTokenArray::AddError() */
+#if 0
+                {
+                    sal_uInt16 n = pElement[ nId ];
+                    if (n < nP_Err)
+                        pScToken->AddError( pP_Err[ n ] );
+                    else
+                        bRet = false;
+                }
 #endif
                 break;
 			case T_RefC:
-				pScToken->AddSingleReference( *ppP_RefTr[ pElement[ (sal_uInt16) nId ] ] );
+                {
+                    sal_uInt16 n = pElement[ nId ];
+                    ScSingleRefData* p = ( n < nP_RefTr )? ppP_RefTr[ n ] : NULL;
+                    if (p)
+                        pScToken->AddSingleReference( *p );
+                    else
+                        bRet = false;
+                }
 				break;
 			case T_RefA:
 				{
-				ScComplexRefData	aScComplexRefData;
-				aScComplexRefData.Ref1 = *ppP_RefTr[ pElement[ nId ] ];
-				aScComplexRefData.Ref2 = *ppP_RefTr[ pElement[ nId ] + 1 ];
-				pScToken->AddDoubleReference( aScComplexRefData );
+                    sal_uInt16 n = pElement[ nId ];
+                    if (n < nP_RefTr && ppP_RefTr[ n ] && n+1 < nP_RefTr && ppP_RefTr[ n + 1 ])
+                    {
+                        ScComplexRefData	aScComplexRefData;
+                        aScComplexRefData.Ref1 = *ppP_RefTr[ n ];
+                        aScComplexRefData.Ref2 = *ppP_RefTr[ n + 1 ];
+                        pScToken->AddDoubleReference( aScComplexRefData );
+                    }
+                    else
+                        bRet = false;
 				}
 				break;
 			case T_RN:
 				pScToken->AddName( pElement[ nId ] );
 				break;
 			case T_Ext:
-				{
-				sal_uInt16			n = pElement[ nId ];
-				EXTCONT*		p = ( n < nP_Ext )? ppP_Ext[ n ] : NULL;
-
-				if( p )
                 {
-                    if( p->eId == ocEuroConvert )
-                        pScToken->AddOpCode( p->eId );
+                    sal_uInt16			n = pElement[ nId ];
+                    EXTCONT*		p = ( n < nP_Ext )? ppP_Ext[ n ] : NULL;
+
+                    if( p )
+                    {
+                        if( p->eId == ocEuroConvert )
+                            pScToken->AddOpCode( p->eId );
+                        else
+                            pScToken->AddExternal( p->aText, p->eId );
+                    }
                     else
-						pScToken->AddExternal( p->aText, p->eId );
+                        bRet = false;
                 }
-				}
 				break;
 			case T_Nlf:
-				{
-				sal_uInt16			n = pElement[ nId ];
-				NLFCONT*		p = ( n < nP_Nlf )? ppP_Nlf[ n ] : NULL;
+                {
+                    sal_uInt16			n = pElement[ nId ];
+                    NLFCONT*		p = ( n < nP_Nlf )? ppP_Nlf[ n ] : NULL;
 
-				if( p )
-						pScToken->AddColRowName( p->aRef );
-				}
+                    if( p )
+                        pScToken->AddColRowName( p->aRef );
+                    else
+                        bRet = false;
+                }
 				break;
             case T_Matrix:
                 {
-                sal_uInt16          n = pElement[ nId ];
-                ScMatrix*       p = ( n < nP_Matrix )? ppP_Matrix[ n ] : NULL;
+                    sal_uInt16          n = pElement[ nId ];
+                    ScMatrix*       p = ( n < nP_Matrix )? ppP_Matrix[ n ] : NULL;
 
-                if( p )
+                    if( p )
                         pScToken->AddMatrix( p );
+                    else
+                        bRet = false;
                 }
                 break;
             case T_ExtName:
-            {
-                sal_uInt16 n = pElement[nId];
-                if (n < maExtNames.size())
                 {
-                    const ExtName& r = maExtNames[n];
-                    pScToken->AddExternalName(r.mnFileId, r.maName);
+                    sal_uInt16 n = pElement[nId];
+                    if (n < maExtNames.size())
+                    {
+                        const ExtName& r = maExtNames[n];
+                        pScToken->AddExternalName(r.mnFileId, r.maName);
+                    }
+                    else
+                        bRet = false;
                 }
-            }
+                break;
             case T_ExtRefC:
-            {
-                sal_uInt16 n = pElement[nId];
-                if (n < maExtCellRefs.size())
                 {
-                    const ExtCellRef& r = maExtCellRefs[n];
-                    pScToken->AddExternalSingleReference(r.mnFileId, r.maTabName, r.maRef);
+                    sal_uInt16 n = pElement[nId];
+                    if (n < maExtCellRefs.size())
+                    {
+                        const ExtCellRef& r = maExtCellRefs[n];
+                        pScToken->AddExternalSingleReference(r.mnFileId, r.maTabName, r.maRef);
+                    }
+                    else
+                        bRet = false;
                 }
-            }
+                break;
             case T_ExtRefA:
-            {
-                sal_uInt16 n = pElement[nId];
-                if (n < maExtAreaRefs.size())
                 {
-                    const ExtAreaRef& r = maExtAreaRefs[n];
-                    pScToken->AddExternalDoubleReference(r.mnFileId, r.maTabName, r.maRef);
+                    sal_uInt16 n = pElement[nId];
+                    if (n < maExtAreaRefs.size())
+                    {
+                        const ExtAreaRef& r = maExtAreaRefs[n];
+                        pScToken->AddExternalDoubleReference(r.mnFileId, r.maTabName, r.maRef);
+                    }
+                    else
+                        bRet = false;
                 }
-            }
-            break;
+                break;
 			default:
-				DBG_ERROR("-TokenPool::GetElement(): Zustand undefiniert!?");
+				DBG_ERROR("-TokenPool::GetElement(): undefined state!?");
+                bRet = false;
 		}
 	}
+    return bRet;
 }
 
 
-void TokenPool::GetElementRek( const sal_uInt16 nId )
+bool TokenPool::GetElementRek( const sal_uInt16 nId )
 {
 #ifdef DBG_UTIL
 	nRek++;
-	DBG_ASSERT( nRek <= nP_Id, "*TokenPool::GetElement(): Rekursion loopt!?" );
+	DBG_ASSERT( nRek <= nP_Id, "*TokenPool::GetElement(): recursion loops" );
 #endif
 
-	DBG_ASSERT( nId < nElementAkt, "*TokenPool::GetElementRek(): Id zu gross!?" );
+    if (nId >= nElementAkt)
+    {
+        DBG_ERRORFILE( "*TokenPool::GetElementRek(): nId >= nElementAkt" );
+#ifdef DBG_UTIL
+        nRek--;
+#endif
+        return false;
+    }
 
-	DBG_ASSERT( pType[ nId ] == T_Id, "-TokenPool::GetElementRek(): nId nicht Id-Folge!" );
+    if (pType[ nId ] != T_Id)
+    {
+        DBG_ERRORFILE( "-TokenPool::GetElementRek(): pType[ nId ] != T_Id" );
+#ifdef DBG_UTIL
+        nRek--;
+#endif
+        return false;
+    }
 
 
-	sal_uInt16		nAnz = pSize[ nId ];
-	sal_uInt16*		pAkt = &pP_Id[ pElement[ nId ] ];
+    bool bRet = true;
+	sal_uInt16 nAnz = pSize[ nId ];
+    sal_uInt16 nFirstId = pElement[ nId ];
+    if (nFirstId >= nP_Id)
+    {
+        DBG_ERRORFILE( "TokenPool::GetElementRek: nFirstId >= nP_Id");
+        nAnz = 0;
+        bRet = false;
+    }
+	sal_uInt16* pAkt = nAnz ? &pP_Id[ nFirstId ] : NULL;
+    if (nAnz > nP_Id - nFirstId)
+    {
+        DBG_ERRORFILE( "TokenPool::GetElementRek: nAnz > nP_Id - nFirstId");
+        nAnz = nP_Id - nFirstId;
+        bRet = false;
+    }
 	for( ; nAnz > 0 ; nAnz--, pAkt++ )
 	{
 		if( *pAkt < nScTokenOff )
 		{// Rekursion oder nicht?
-			switch( pType[ *pAkt ] )
-			{
-				case T_Id:
-					GetElementRek( *pAkt );
-					break;
-				case T_Str:
-					pScToken->AddString( ppP_Str[ pElement[ *pAkt ] ]->GetBuffer() );
-					break;
-				case T_D:
-					pScToken->AddDouble( pP_Dbl[ pElement[ *pAkt ] ] );
-					break;
-                case T_Err:
-#if 0   // erAck
-                    pScToken->AddError( pP_Err[ pElement[ *pAkt ] ] );
-#endif
-                    break;
-				case T_RefC:
-					pScToken->AddSingleReference( *ppP_RefTr[ pElement[ *pAkt ] ] );
-					break;
-				case T_RefA:
-					{
-					ScComplexRefData	aScComplexRefData;
-					aScComplexRefData.Ref1 = *ppP_RefTr[ pElement[ *pAkt ] ];
-					aScComplexRefData.Ref2 = *ppP_RefTr[ pElement[ *pAkt ] + 1 ];
-					pScToken->AddDoubleReference( aScComplexRefData );
-					}
-					break;
-				case T_RN:
-					pScToken->AddName( pElement[ *pAkt ] );
-					break;
-				case T_Ext:
-					{
-					sal_uInt16		n = pElement[ *pAkt ];
-					EXTCONT*	p = ( n < nP_Ext )? ppP_Ext[ n ] : NULL;
-
-					if( p )
-						pScToken->AddExternal( p->aText, p->eId );
-					}
-					break;
-				case T_Nlf:
-					{
-					sal_uInt16		n = pElement[ *pAkt ];
-					NLFCONT*	p = ( n < nP_Nlf )? ppP_Nlf[ n ] : NULL;
-
-					if( p )
-						pScToken->AddColRowName( p->aRef );
-					}
-					break;
-                case T_Matrix:
-                    {
-                    sal_uInt16          n = pElement[ *pAkt ];
-                    ScMatrix*       p = ( n < nP_Matrix )? ppP_Matrix[ n ] : NULL;
-
-                    if( p )
-                            pScToken->AddMatrix( p );
-                    }
-                    break;
-                case T_ExtName:
-                {
-                    sal_uInt16 n = pElement[*pAkt];
-                    if (n < maExtNames.size())
-                    {
-                        const ExtName& r = maExtNames[n];
-                        pScToken->AddExternalName(r.mnFileId, r.maName);
-                    }
-                }
-                case T_ExtRefC:
-                {
-                    sal_uInt16 n = pElement[*pAkt];
-                    if (n < maExtCellRefs.size())
-                    {
-                        const ExtCellRef& r = maExtCellRefs[n];
-                        pScToken->AddExternalSingleReference(r.mnFileId, r.maTabName, r.maRef);
-                    }
-                }
-                case T_ExtRefA:
-                {
-                    sal_uInt16 n = pElement[*pAkt];
-                    if (n < maExtAreaRefs.size())
-                    {
-                        const ExtAreaRef& r = maExtAreaRefs[n];
-                        pScToken->AddExternalDoubleReference(r.mnFileId, r.maTabName, r.maRef);
-                    }
-                }
-                break;
-				default:
-					DBG_ERROR("-TokenPool::GetElementRek(): Zustand undefiniert!?");
-			}
+            if (*pAkt >= nElementAkt)
+            {
+                DBG_ERRORFILE( "TokenPool::GetElementRek: *pAkt >= nElementAkt");
+                bRet = false;
+            }
+            else
+            {
+                if (pType[ *pAkt ] == T_Id)
+                    bRet = GetElementRek( *pAkt );
+                else
+                    bRet = GetElement( *pAkt );
+            }
 		}
 		else	// elementarer SC_Token
 			pScToken->AddOpCode( ( DefTokenId ) ( *pAkt - nScTokenOff ) );
 	}
 
-
 #ifdef DBG_UTIL
 	nRek--;
 #endif
+    return bRet;
 }
 
 
@@ -552,7 +615,8 @@ void TokenPool::operator >>( TokenId& rI
 	rId = ( TokenId ) ( nElementAkt + 1 );
 
 	if( nElementAkt >= nElement )
-		GrowElement();
+		if (!GrowElement())
+            return;
 
 	pElement[ nElementAkt ] = nP_IdLast;	// Start der Token-Folge
 	pType[ nElementAkt ] = T_Id;			// Typinfo eintragen
@@ -567,10 +631,12 @@ void TokenPool::operator >>( TokenId& rI
 const TokenId TokenPool::Store( const double& rDouble )
 {
 	if( nElementAkt >= nElement )
-		GrowElement();
+		if (!GrowElement())
+            return (const TokenId) nElementAkt+1;
 
 	if( nP_DblAkt >= nP_Dbl )
-		GrowDouble();
+		if (!GrowDouble())
+            return (const TokenId) nElementAkt+1;
 
 	pElement[ nElementAkt ] = nP_DblAkt;	// Index in Double-Array
 	pType[ nElementAkt ] = T_D;				// Typinfo Double eintragen
@@ -589,7 +655,8 @@ const TokenId TokenPool::Store( const do
 const TokenId TokenPool::Store( const sal_uInt16 nIndex )
 {
 	if( nElementAkt >= nElement )
-		GrowElement();
+		if (!GrowElement())
+            return (const TokenId) nElementAkt+1;
 
 	pElement[ nElementAkt ] = nIndex;			// Daten direkt im Index!
 	pType[ nElementAkt ] = T_RN;				// Typinfo Range Name eintragen
@@ -604,10 +671,12 @@ const TokenId TokenPool::Store( const St
 	// weitgehend nach Store( const sal_Char* ) kopiert, zur Vermeidung
 	//  eines temporaeren Strings in "
 	if( nElementAkt >= nElement )
-		GrowElement();
+		if (!GrowElement())
+            return (const TokenId) nElementAkt+1;
 
 	if( nP_StrAkt >= nP_Str )
-		GrowString();
+		if (!GrowString())
+            return (const TokenId) nElementAkt+1;
 
 	pElement[ nElementAkt ] = nP_StrAkt;	// Index in String-Array
 	pType[ nElementAkt ] = T_Str;			// Typinfo String eintragen
@@ -615,14 +684,16 @@ const TokenId TokenPool::Store( const St
 	// String anlegen
 	if( !ppP_Str[ nP_StrAkt ] )
 		//...aber nur, wenn noch nicht vorhanden
-		ppP_Str[ nP_StrAkt ] = new String( rString );
+		ppP_Str[ nP_StrAkt ] = new (::std::nothrow) String( rString );
 	else
 		//...ansonsten nur kopieren
 		*ppP_Str[ nP_StrAkt ] = rString;
 
-	DBG_ASSERT( sizeof( xub_StrLen ) <= 2, "*TokenPool::Store(): StrLen doesn't match!" );
-
-	pSize[ nElementAkt ] = ( sal_uInt16 ) ppP_Str[ nP_StrAkt ]->Len();
+    if (ppP_Str[ nP_StrAkt ])
+    {
+        DBG_ASSERT( sizeof( xub_StrLen ) <= 2, "*TokenPool::Store(): StrLen doesn't match!" );
+        pSize[ nElementAkt ] = ( sal_uInt16 ) ppP_Str[ nP_StrAkt ]->Len();
+    }
 
 	nElementAkt++;
 	nP_StrAkt++;
@@ -634,10 +705,12 @@ const TokenId TokenPool::Store( const St
 const TokenId TokenPool::Store( const ScSingleRefData& rTr )
 {
 	if( nElementAkt >= nElement )
-		GrowElement();
+		if (!GrowElement())
+            return (const TokenId) nElementAkt+1;
 
 	if( nP_RefTrAkt >= nP_RefTr )
-		GrowTripel();
+		if (!GrowTripel())
+            return (const TokenId) nElementAkt+1;
 
 	pElement[ nElementAkt ] = nP_RefTrAkt;
 	pType[ nElementAkt ] = T_RefC;			// Typinfo Cell-Reff eintragen
@@ -657,10 +730,12 @@ const TokenId TokenPool::Store( const Sc
 const TokenId TokenPool::Store( const ScComplexRefData& rTr )
 {
 	if( nElementAkt >= nElement )
-		GrowElement();
+		if (!GrowElement())
+            return (const TokenId) nElementAkt+1;
 
 	if( nP_RefTrAkt + 1 >= nP_RefTr )
-		GrowTripel();
+		if (!GrowTripel( 2))
+            return (const TokenId) nElementAkt+1;
 
 	pElement[ nElementAkt ] = nP_RefTrAkt;
 	pType[ nElementAkt ] = T_RefA;			// Typinfo Area-Reff eintragen
@@ -686,10 +761,12 @@ const TokenId TokenPool::Store( const Sc
 const TokenId TokenPool::Store( const DefTokenId e, const String& r )
 {
 	if( nElementAkt >= nElement )
-		GrowElement();
+		if (!GrowElement())
+            return (const TokenId) nElementAkt+1;
 
 	if( nP_ExtAkt >= nP_Ext )
-        GrowExt();
+        if (!GrowExt())
+            return (const TokenId) nElementAkt+1;
 
 	pElement[ nElementAkt ] = nP_ExtAkt;
 	pType[ nElementAkt ] = T_Ext;			// Typinfo String eintragen
@@ -712,10 +789,12 @@ const TokenId TokenPool::Store( const De
 const TokenId TokenPool::StoreNlf( const ScSingleRefData& rTr )
 {
 	if( nElementAkt >= nElement )
-		GrowElement();
+		if (!GrowElement())
+            return (const TokenId) nElementAkt+1;
 
 	if( nP_NlfAkt >= nP_Nlf )
-		GrowNlf();
+		if (!GrowNlf())
+            return (const TokenId) nElementAkt+1;
 
 	pElement[ nElementAkt ] = nP_NlfAkt;
 	pType[ nElementAkt ] = T_Nlf;
@@ -738,10 +817,12 @@ const TokenId TokenPool::StoreMatrix()
     ScMatrix* pM;
 
     if( nElementAkt >= nElement )
-        GrowElement();
+		if (!GrowElement())
+            return (const TokenId) nElementAkt+1;
 
     if( nP_MatrixAkt >= nP_Matrix )
-        GrowMatrix();
+        if (!GrowMatrix())
+            return (const TokenId) nElementAkt+1;
 
     pElement[ nElementAkt ] = nP_MatrixAkt;
     pType[ nElementAkt ] = T_Matrix;
@@ -759,7 +840,8 @@ const TokenId TokenPool::StoreMatrix()
 const TokenId TokenPool::StoreExtName( sal_uInt16 nFileId, const String& rName )
 {
     if ( nElementAkt >= nElement )
-        GrowElement();
+		if (!GrowElement())
+            return (const TokenId) nElementAkt+1;
 
     pElement[nElementAkt] = static_cast<sal_uInt16>(maExtNames.size());
     pType[nElementAkt] = T_ExtName;
@@ -777,7 +859,8 @@ const TokenId TokenPool::StoreExtName( s
 const TokenId TokenPool::StoreExtRef( sal_uInt16 nFileId, const String& rTabName, const ScSingleRefData& rRef )
 {
     if ( nElementAkt >= nElement )
-        GrowElement();
+		if (!GrowElement())
+            return (const TokenId) nElementAkt+1;
 
     pElement[nElementAkt] = static_cast<sal_uInt16>(maExtCellRefs.size());
     pType[nElementAkt] = T_ExtRefC;
@@ -796,7 +879,8 @@ const TokenId TokenPool::StoreExtRef( sa
 const TokenId TokenPool::StoreExtRef( sal_uInt16 nFileId, const String& rTabName, const ScComplexRefData& rRef )
 {
     if ( nElementAkt >= nElement )
-        GrowElement();
+		if (!GrowElement())
+            return (const TokenId) nElementAkt+1;
 
     pElement[nElementAkt] = static_cast<sal_uInt16>(maExtAreaRefs.size());
     pType[nElementAkt] = T_ExtRefA;
@@ -831,11 +915,15 @@ sal_Bool TokenPool::IsSingleOp( const To
 		{// Tokenfolge?
 			if( pSize[ nId ] == 1 )
 			{// GENAU 1 Token
-				sal_uInt16	nSecId = pP_Id[ pElement[ nId ] ];
-				if( nSecId >= nScTokenOff )
-				{// Default-Token?
-					return ( DefTokenId ) ( nSecId - nScTokenOff ) == eId;	// Gesuchter?
-				}
+                sal_uInt16 nPid = pElement[ nId ];
+                if (nPid < nP_Id)
+                {
+                    sal_uInt16	nSecId = pP_Id[ nPid ];
+                    if( nSecId >= nScTokenOff )
+                    {// Default-Token?
+                        return ( DefTokenId ) ( nSecId - nScTokenOff ) == eId;	// Gesuchter?
+                    }
+                }
 			}
 		}
 	}
@@ -851,28 +939,17 @@ const String* TokenPool::GetExternal( co
 	if( n && n <= nElementAkt )
 	{
 		n--;
-        if( (pType[ n ] == T_Ext) && ppP_Ext[ pElement[ n ] ] )
-            p = &ppP_Ext[ pElement[ n ] ]->aText;
+        if( (pType[ n ] == T_Ext) )
+        {
+            sal_uInt16 nExt = pElement[ n ];
+            if ( nExt < nP_Ext && ppP_Ext[ nExt ] )
+                p = &ppP_Ext[ nExt ]->aText;
+        }
 	}
 
     return p;
 }
 
-
-//UNUSED2008-05  const String* TokenPool::GetString( const TokenId& r ) const
-//UNUSED2008-05  {
-//UNUSED2008-05      const String*   p = NULL;
-//UNUSED2008-05      sal_uInt16 n = (sal_uInt16) r;
-//UNUSED2008-05      if( n && n <= nElementAkt )
-//UNUSED2008-05      {
-//UNUSED2008-05          n--;
-//UNUSED2008-05          if( pType[ n ] == T_Str )
-//UNUSED2008-05              p = ppP_Str[ pElement[ n ] ];
-//UNUSED2008-05      }
-//UNUSED2008-05  
-//UNUSED2008-05      return p;
-//UNUSED2008-05  }
-
 ScMatrix* TokenPool::GetMatrix( unsigned int n ) const
 {
     if( n < nP_MatrixAkt )

Modified: incubator/ooo/trunk/main/sc/source/filter/inc/lotfntbf.hxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sc/source/filter/inc/lotfntbf.hxx?rev=1362886&r1=1362885&r2=1362886&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sc/source/filter/inc/lotfntbf.hxx (original)
+++ incubator/ooo/trunk/main/sc/source/filter/inc/lotfntbf.hxx Wed Jul 18 11:26:13 2012
@@ -92,14 +92,15 @@ private:
 		inline void			Type( const sal_uInt16 nNew )		{ nType = nNew; }
 	};
 
-	ENTRY					pData[ 8 ];
-	const static sal_uInt16		nSize;
 	void					MakeFont( ENTRY* pEntry );
 public:
+	const static sal_uInt16	nSize = 8;
 	void					Fill( const sal_uInt8 nIndex, SfxItemSet& rItemSet );
 	void					SetName( const sal_uInt16 nIndex, const String& rName );
 	void					SetHeight( const sal_uInt16 nIndex, const sal_uInt16 nHeight );
 	void					SetType( const sal_uInt16 nIndex, const sal_uInt16 nType );
+private:
+	ENTRY					pData[ nSize ];
 };
 
 

Modified: incubator/ooo/trunk/main/sc/source/filter/inc/lotimpop.hxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sc/source/filter/inc/lotimpop.hxx?rev=1362886&r1=1362885&r2=1362886&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sc/source/filter/inc/lotimpop.hxx (original)
+++ incubator/ooo/trunk/main/sc/source/filter/inc/lotimpop.hxx Wed Jul 18 11:26:13 2012
@@ -41,7 +41,6 @@ class ImportLotus : public ImportTyp
 {
 private:
 	SvStream*			pIn;			// benoetigt wegen multiplem Read()!
-	LotusFontBuffer*	pFontBuff;
 	LotusToSc			aConv;
     sal_uInt16              nTab;           // z.Zt. bearbeitete Tabelle
 	sal_Int32				nExtTab;

Modified: incubator/ooo/trunk/main/sc/source/filter/inc/op.h
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sc/source/filter/inc/op.h?rev=1362886&r1=1362885&r2=1362886&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sc/source/filter/inc/op.h (original)
+++ incubator/ooo/trunk/main/sc/source/filter/inc/op.h Wed Jul 18 11:26:13 2012
@@ -35,7 +35,6 @@ void OP_EOF( SvStream &aStream, sal_uInt
 void OP_Integer( SvStream &aStream, sal_uInt16 nLaenge );
 void OP_Number( SvStream &aStream, sal_uInt16 nLaenge );
 void OP_Label( SvStream &aStream, sal_uInt16 nLaenge );
-//UNUSED2009-05 void OP_Text( SvStream &aStream, sal_uInt16 nLaenge );		// WK3
 void OP_Integer3( SvStream &aStream, sal_uInt16 nLaenge );	// WK3
 void OP_Number3( SvStream &aStream, sal_uInt16 nLaenge );	// WK3
 void OP_Formula( SvStream &aStream, sal_uInt16 nLaenge );

Modified: incubator/ooo/trunk/main/sc/source/filter/inc/root.hxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sc/source/filter/inc/root.hxx?rev=1362886&r1=1362885&r2=1362886&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sc/source/filter/inc/root.hxx (original)
+++ incubator/ooo/trunk/main/sc/source/filter/inc/root.hxx Wed Jul 18 11:26:13 2012
@@ -105,6 +105,9 @@ struct LOTUS_ROOT
 	RangeNameBufferWK3*	pRngNmBffWK3;
 	LotusFontBuffer*	pFontBuff;
 	LotAttrTable*		pAttrTable;
+
+                        LOTUS_ROOT( ScDocument* pDocP, CharSet eQ );
+                        ~LOTUS_ROOT();
 };
 
 extern LOTUS_ROOT*		pLotusRoot;	// -> Inkarn. in filter.cxx

Modified: incubator/ooo/trunk/main/sc/source/filter/inc/tokstack.hxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sc/source/filter/inc/tokstack.hxx?rev=1362886&r1=1362885&r2=1362886&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sc/source/filter/inc/tokstack.hxx (original)
+++ incubator/ooo/trunk/main/sc/source/filter/inc/tokstack.hxx Wed Jul 18 11:26:13 2012
@@ -170,17 +170,20 @@ class TokenPool
 #endif
 		ScTokenArray*				pScToken;	// Tokenbastler
 
-		void						GrowString( void );
-		void						GrowDouble( void );
-//UNUSED2009-05 void                        GrowError( void );
-		void						GrowTripel( void );
-		void						GrowId( void );
-		void						GrowElement( void );
-		void						GrowExt( void );
-		void						GrowNlf( void );
-		void						GrowMatrix( void );
-		void						GetElement( const sal_uInt16 nId );
-		void						GetElementRek( const sal_uInt16 nId );
+		bool						GrowString( void );
+		bool						GrowDouble( void );
+/* TODO: in case we had FormulaTokenArray::AddError() */
+#if 0
+        bool                        GrowError( void );
+#endif
+		bool						GrowTripel( sal_uInt16 nByMin = 1 );
+		bool						GrowId( void );
+		bool						GrowElement( void );
+		bool						GrowExt( void );
+		bool						GrowNlf( void );
+		bool						GrowMatrix( void );
+		bool						GetElement( const sal_uInt16 nId );
+		bool						GetElementRek( const sal_uInt16 nId );
 	public:
 									TokenPool( void );
 									~TokenPool();
@@ -214,7 +217,6 @@ class TokenPool
 		inline E_TYPE				GetType( const TokenId& nId ) const;
 		sal_Bool						IsSingleOp( const TokenId& nId, const DefTokenId eId ) const;
         const String*               GetExternal( const TokenId& nId ) const;
-//UNUSED2008-05  const String*               GetString( const TokenId& nId ) const;
 		ScMatrix*					GetMatrix( unsigned int n ) const;
 };
 
@@ -305,7 +307,8 @@ inline TokenPool& TokenPool::operator <<
 		"-TokenPool::operator <<: TokenId im DefToken-Bereich!" );
 
 	if( nP_IdAkt >= nP_Id )
-		GrowId();
+		if (!GrowId())
+            return *this;
 
 	pP_Id[ nP_IdAkt ] = ( ( sal_uInt16 ) nId ) - 1;
 	nP_IdAkt++;
@@ -320,7 +323,8 @@ inline TokenPool& TokenPool::operator <<
 		"-TokenPool::operator<<: enmum zu gross!" );
 
 	if( nP_IdAkt >= nP_Id )
-		GrowId();
+		if (!GrowId())
+            return *this;
 
 	pP_Id[ nP_IdAkt ] = ( ( sal_uInt16 ) eId ) + nScTokenOff;
 	nP_IdAkt++;
@@ -332,7 +336,8 @@ inline TokenPool& TokenPool::operator <<
 inline TokenPool& TokenPool::operator <<( TokenStack& rStack )
 {
 	if( nP_IdAkt >= nP_Id )
-		GrowId();
+		if (!GrowId())
+            return *this;
 
 	pP_Id[ nP_IdAkt ] = ( ( sal_uInt16 ) rStack.Get() ) - 1;
 	nP_IdAkt++;

Modified: incubator/ooo/trunk/main/sc/source/filter/lotus/filter.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sc/source/filter/lotus/filter.cxx?rev=1362886&r1=1362885&r2=1362886&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sc/source/filter/lotus/filter.cxx (original)
+++ incubator/ooo/trunk/main/sc/source/filter/lotus/filter.cxx Wed Jul 18 11:26:13 2012
@@ -60,9 +60,6 @@ WKTYP				eTyp;
 extern sal_Bool			bEOF;			// zeigt Ende der Datei
 sal_Bool				bEOF;
 
-extern CharSet		eCharNach;		// Zeichenkonvertierung von->nach
-CharSet				eCharNach;
-
 extern CharSet		eCharVon;
 CharSet				eCharVon;
 
@@ -70,16 +67,11 @@ extern ScDocument*	pDoc;			// Aufhaenger
 ScDocument*			pDoc;
 
 
-extern sal_Char*	pPuffer;		// -> memory.cxx
-extern sal_Char*	pDummy1;		// -> memory.cxx
-
 extern OPCODE_FKT	pOpFkt[ FKT_LIMIT ];
 									// -> optab.cxx, Tabelle moeglicher Opcodes
 extern OPCODE_FKT	pOpFkt123[ FKT_LIMIT123 ];
 									// -> optab.cxx, Table of possible Opcodes
 
-extern long			nDateiLaenge;	// -> datei.cpp, ...der gerade offenen Datei
-
 LOTUS_ROOT*			pLotusRoot = NULL;
 
 
@@ -193,9 +185,10 @@ WKTYP ScanVersion( SvStream& aStream )
 			aStream >> nVersNr;
 			if( aStream.IsEof() ) return eWK_Error;
 			if( nVersNr == 0x0004 && nRecLen == 26 )
-			{	// 4 Bytes von 26 gelesen->22 ueberlesen
-				aStream.Read( pDummy1, 22 );
-				return eWK3;
+			{	// 4 bytes of 26 read => skip 22 (read instead of seek to make IsEof() work just in case)
+                sal_Char aDummy[22];
+                aStream.Read( aDummy, 22 );
+                return aStream.IsEof() ? eWK_Error : eWK3;
 			}
 			break;
 		case 0x1003:

Modified: incubator/ooo/trunk/main/sc/source/filter/lotus/lotattr.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sc/source/filter/lotus/lotattr.cxx?rev=1362886&r1=1362885&r2=1362886&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sc/source/filter/lotus/lotattr.cxx (original)
+++ incubator/ooo/trunk/main/sc/source/filter/lotus/lotattr.cxx Wed Jul 18 11:26:13 2012
@@ -68,7 +68,7 @@ void LotAttrCache::LotusToScBorderLine( 
 const SvxColorItem& LotAttrCache::GetColorItem( const sal_uInt8 nLotIndex ) const
 {
 	DBG_ASSERT( nLotIndex > 0 && nLotIndex < 7,
-		"-LotAttrCache::GetColorItem(): so nicht!" );
+		"-LotAttrCache::GetColorItem(): caller hast to check index!" );
 
 	return *ppColorItems[ nLotIndex - 1 ];
 }
@@ -77,7 +77,7 @@ const SvxColorItem& LotAttrCache::GetCol
 const Color& LotAttrCache::GetColor( const sal_uInt8 nLotIndex ) const
 {
 	// Farbe <-> Index passt fuer Background, nicht aber fuer Fonts (0 <-> 7)!
-	DBG_ASSERT( nLotIndex < 8, "*LotAttrCache::GetColor(): Index > 7!" );
+	DBG_ASSERT( nLotIndex < 8, "*LotAttrCache::GetColor(): Index > 7, caller hast to check index!" );
 	return pColTab[ nLotIndex ];
 }
 
@@ -208,6 +208,8 @@ LotAttrCol::~LotAttrCol()
 
 void LotAttrCol::SetAttr( const SCROW nRow, const ScPatternAttr& rAttr )
 {
+    // Actually with the current implementation of MAXROWCOUNT>=64k and nRow 
+    // being read as sal_uInt16 there's no chance that nRow would be invalid..
 	DBG_ASSERT( ValidRow(nRow), "*LotAttrCol::SetAttr(): ... und rums?!" );
 
 	ENTRY*		pAkt = ( ENTRY* ) List::Last();
@@ -275,6 +277,9 @@ LotAttrTable::~LotAttrTable()
 void LotAttrTable::SetAttr( const SCCOL nColFirst, const SCCOL nColLast, const SCROW nRow,
 							const LotAttrWK3& rAttr )
 {
+    // With the current implementation of MAXCOLCOUNT>=1024 and nColFirst and 
+    // nColLast being calculated as sal_uInt8+sal_uInt8 there's no chance that 
+    // they would be invalid.
 	const ScPatternAttr&	rPattAttr = aAttrCache.GetPattAttr( rAttr );
 	SCCOL					nColCnt;
 

Modified: incubator/ooo/trunk/main/sc/source/filter/lotus/lotform.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sc/source/filter/lotus/lotform.cxx?rev=1362886&r1=1362885&r2=1362886&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sc/source/filter/lotus/lotform.cxx (original)
+++ incubator/ooo/trunk/main/sc/source/filter/lotus/lotform.cxx Wed Jul 18 11:26:13 2012
@@ -121,7 +121,8 @@ void LotusToSc::DoFunc( DefTokenId eOc, 
 			break;
 		case ocChose:
 		{// 1. Parameter ++
-			IncToken( eParam[ nAnz - 1 ] );
+            if (nAnz >= 1)
+                IncToken( eParam[ nAnz - 1 ] );
 		}
 			break;
 		case ocFind:
@@ -134,7 +135,8 @@ void LotusToSc::DoFunc( DefTokenId eOc, 
 		case ocMid:
 		case ocReplace:
 		{// 2. Parameter ++
-			IncToken( eParam[ nAnz - 2 ] );
+            if (nAnz >= 2)
+                IncToken( eParam[ nAnz - 2 ] );
 		}
 			break;
 		case ocZins:
@@ -604,14 +606,18 @@ ConvErr LotusToSc::Convert( const ScToke
 
 				if( nStrLen )
 				{
-//					String	t( ReadString( aIn, nStrLen, eSrcChar ) );
-					sal_Char*	p = new sal_Char[ nStrLen + 1 ];
-					aIn.Read( p, nStrLen );
-					p[ nStrLen ] = 0x00;
-
-					DoFunc( ocNoName, nAnz, p );
-
-					delete[] p;
+					sal_Char*	p = new (::std::nothrow) sal_Char[ nStrLen + 1 ];
+                    if (p)
+                    {
+                        aIn.Read( p, nStrLen );
+                        p[ nStrLen ] = 0x00;
+
+                        DoFunc( ocNoName, nAnz, p );
+
+                        delete[] p;
+                    }
+                    else
+                        DoFunc( ocNoName, nAnz, NULL );
 				}
 				else
 					DoFunc( ocNoName, nAnz, NULL );
@@ -1991,7 +1997,7 @@ const sal_Char* GetAddInName( const sal_
 }
 
 
-DefTokenId lcl_KnownAddIn( const ByteString& sTest )
+static DefTokenId lcl_KnownAddIn( const ByteString& sTest )
 {
 	DefTokenId	eId = ocNoName;
 

Modified: incubator/ooo/trunk/main/sc/source/filter/lotus/lotimpop.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sc/source/filter/lotus/lotimpop.cxx?rev=1362886&r1=1362885&r2=1362886&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sc/source/filter/lotus/lotimpop.cxx (original)
+++ incubator/ooo/trunk/main/sc/source/filter/lotus/lotimpop.cxx Wed Jul 18 11:26:13 2012
@@ -46,6 +46,29 @@
 
 static vos:: OMutex 		aLotImpSemaphore;
 
+LOTUS_ROOT::LOTUS_ROOT( ScDocument* pDocP, CharSet eQ )
+    :
+        pDoc( pDocP),
+        pRangeNames( new LotusRangeList),
+        pScRangeName( pDocP->GetRangeName()),
+        eCharsetQ( eQ),
+        eFirstType( Lotus_X),
+        eActType( Lotus_X),
+        pRngNmBffWK3( new RangeNameBufferWK3),
+        pFontBuff( new LotusFontBuffer),
+        pAttrTable( new LotAttrTable)
+{
+}
+
+
+LOTUS_ROOT::~LOTUS_ROOT()
+{
+	delete pRangeNames;
+	delete pRngNmBffWK3;
+	delete pFontBuff;
+	delete pAttrTable;
+}
+
 
 ImportLotus::ImportLotus( SvStream& aStream, ScDocument* pDoc, CharSet eQ ) :
     ImportTyp( pDoc, eQ ),
@@ -55,30 +78,14 @@ ImportLotus::ImportLotus( SvStream& aStr
 	// good point to start locking of import lotus
 	aLotImpSemaphore.acquire();
 
-	pLotusRoot = new LOTUS_ROOT;
-	pLotusRoot->pDoc = pDoc;
-	pLotusRoot->pRangeNames = new LotusRangeList;
-	pLotusRoot->pScRangeName = pDoc->GetRangeName();
-	pLotusRoot->eCharsetQ = eQ;
-	pLotusRoot->eFirstType = Lotus_X;
-	pLotusRoot->eActType = Lotus_X;
-	pLotusRoot->pRngNmBffWK3 = new RangeNameBufferWK3;
-	pFontBuff = pLotusRoot->pFontBuff = new LotusFontBuffer;
-	pLotusRoot->pAttrTable = new LotAttrTable;
+	pLotusRoot = new LOTUS_ROOT( pDoc, eQ);
 }
 
 
 ImportLotus::~ImportLotus()
 {
-	delete pLotusRoot->pRangeNames;
-	delete pLotusRoot->pRngNmBffWK3;
-	delete pFontBuff;
-	delete pLotusRoot->pAttrTable;
 	delete pLotusRoot;
-
-#ifdef DBG_UTIL
 	pLotusRoot = NULL;
-#endif
 
 	// no need 4 pLotusRoot anymore
 	aLotImpSemaphore.release();
@@ -129,7 +136,7 @@ void ImportLotus::Columnwidth( sal_uInt1
 	DBG_ASSERT( nRecLen >= 4, "*ImportLotus::Columnwidth(): Record zu kurz!" );
 
     sal_uInt8    nLTab, nWindow2;
-	sal_uInt16	nCnt = ( nRecLen - 4 ) / 2;
+	sal_uInt16	nCnt = (nRecLen < 4) ? 0 : ( nRecLen - 4 ) / 2;
 
     Read( nLTab );
 	Read( nWindow2 );
@@ -161,7 +168,7 @@ void ImportLotus::Hiddencolumn( sal_uInt
 	DBG_ASSERT( nRecLen >= 4, "*ImportLotus::Hiddencolumn(): Record zu kurz!" );
 
     sal_uInt8    nLTab, nWindow2;
-	sal_uInt16	nCnt = ( nRecLen - 4 ) / 2;
+	sal_uInt16	nCnt = (nRecLen < 4) ? 0 : ( nRecLen - 4 ) / 2;
 
     Read( nLTab );
 	Read( nWindow2 );
@@ -187,18 +194,17 @@ void ImportLotus::Userrange( void )
 {
 	sal_uInt16		nRangeType;
 	ScRange		aScRange;
-	sal_Char*	pBuffer = new sal_Char[ 32 ];
 
 	Read( nRangeType );
 
-	pIn->Read( pBuffer, 16 );
-	pBuffer[ 16 ] = ( sal_Char ) 0x00;	// zur Sicherheit...
-	String		aName( pBuffer, eQuellChar );
+	sal_Char aBuffer[ 17 ];
+	pIn->Read( aBuffer, 16 );
+	aBuffer[ 16 ] = 0;
+	String		aName( aBuffer, eQuellChar );
 
 	Read( aScRange );
 
 	pLotusRoot->pRngNmBffWK3->Add( aName, aScRange );
-	delete[] pBuffer;
 }
 
 
@@ -239,7 +245,7 @@ void ImportLotus::Labelcell( void )
 
 
 void ImportLotus::Numbercell( void )
-	{
+{
 	ScAddress	aAddr;
 	double		fVal;
 
@@ -248,11 +254,11 @@ void ImportLotus::Numbercell( void )
 
 	pD->PutCell( aAddr.Col(), aAddr.Row(), aAddr.Tab(),
 		new ScValueCell( fVal ), (sal_Bool)sal_True );
-	}
+}
 
 
 void ImportLotus::Smallnumcell( void )
-	{
+{
 	ScAddress	aAddr;
 	sal_Int16		nVal;
 
@@ -261,11 +267,11 @@ void ImportLotus::Smallnumcell( void )
 
 	pD->PutCell( aAddr.Col(), aAddr.Row(), aAddr.Tab(),
 		new ScValueCell( SnumToDouble( nVal ) ), ( sal_Bool ) sal_True );
-	}
+}
 
 
 ScFormulaCell *ImportLotus::Formulacell( sal_uInt16 n )
-	{
+{
 	DBG_ASSERT( pIn, "-ImportLotus::Formulacell(): Null-Stream -> Rums!" );
 
 	ScAddress			aAddr;
@@ -273,7 +279,7 @@ ScFormulaCell *ImportLotus::Formulacell(
 	Read( aAddr );
 	Skip( 10 );
 
-	n -= 14;
+	n -= (n > 14) ? 14 : n;
 
 	const ScTokenArray*	pErg;
 	sal_Int32				nRest = n;
@@ -289,7 +295,7 @@ ScFormulaCell *ImportLotus::Formulacell(
 	pD->PutCell( aAddr.Col(), aAddr.Row(), aAddr.Tab(), pZelle, (sal_Bool)sal_True );
 
 	return NULL;
-	}
+}
 
 
 void ImportLotus::Read( String &r )
@@ -304,7 +310,7 @@ void ImportLotus::RowPresentation( sal_u
 
     sal_uInt8    nLTab, nFlags;
 	sal_uInt16	nRow, nHeight;
-	sal_uInt16	nCnt = ( nRecLen - 4 ) / 8;
+	sal_uInt16	nCnt = (nRecLen < 4) ? 0 : ( nRecLen - 4 ) / 8;
 
     Read( nLTab );
 	Skip( 1 );
@@ -355,52 +361,44 @@ void ImportLotus::Font_Face( void )
 
 	Read( nNum );
 
-	// ACHTUNG: QUICK-HACK gegen unerklaerliche Loops
-	if( nNum > 7 )
-		return;
-	// ACHTUNG
+	if( nNum >= LotusFontBuffer::nSize )
+		return;     // nonsense
 
 	Read( aName );
 
-	pFontBuff->SetName( nNum, aName );
+	pLotusRoot->pFontBuff->SetName( nNum, aName );
 }
 
 
 void ImportLotus::Font_Type( void )
 {
-	static const sal_uInt16 nAnz = 8;
-	sal_uInt16				nCnt;
-	sal_uInt16				nType;
-
-	for( nCnt = 0 ; nCnt < nAnz ; nCnt++ )
+	for( sal_uInt16 nCnt = 0 ; nCnt < LotusFontBuffer::nSize ; nCnt++ )
 	{
+        sal_uInt16 nType;
 		Read( nType );
-		pFontBuff->SetType( nCnt, nType );
+		pLotusRoot->pFontBuff->SetType( nCnt, nType );
 	}
 }
 
 
 void ImportLotus::Font_Ysize( void )
 {
-	static const sal_uInt16	nAnz = 8;
-	sal_uInt16				nCnt;
-	sal_uInt16				nSize;
-
-	for( nCnt = 0 ; nCnt < nAnz ; nCnt++ )
+	for( sal_uInt16 nCnt = 0 ; nCnt < LotusFontBuffer::nSize ; nCnt++ )
 	{
+        sal_uInt16 nSize;
 		Read( nSize );
-		pFontBuff->SetHeight( nCnt, nSize );
+		pLotusRoot->pFontBuff->SetHeight( nCnt, nSize );
 	}
 }
 
 
 void ImportLotus::_Row( const sal_uInt16 nRecLen )
-	{
+{
 	DBG_ASSERT( nExtTab >= 0, "*ImportLotus::_Row(): Kann hier nicht sein!" );
 
 	sal_uInt16			nRow;
 	sal_uInt16			nHeight;
-	sal_uInt16			nCntDwn = ( nRecLen - 4 ) / 5;
+	sal_uInt16			nCntDwn = (nRecLen < 4) ? 0 : ( nRecLen - 4 ) / 5;
 	SCCOL			nColCnt = 0;
 	sal_uInt8			nRepeats;
 	LotAttrWK3		aAttr;
@@ -464,6 +462,4 @@ void ImportLotus::_Row( const sal_uInt16
 	if( bCenter )
 		// evtl. alte Center bemachen
 		pD->DoMerge( static_cast<SCTAB> (nExtTab), nCenterStart, static_cast<SCROW> (nRow), nCenterEnd, static_cast<SCROW> (nRow) );
-	}
-
-
+}

Modified: incubator/ooo/trunk/main/sc/source/filter/lotus/lotread.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sc/source/filter/lotus/lotread.cxx?rev=1362886&r1=1362885&r2=1362886&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sc/source/filter/lotus/lotread.cxx (original)
+++ incubator/ooo/trunk/main/sc/source/filter/lotus/lotread.cxx Wed Jul 18 11:26:13 2012
@@ -73,7 +73,7 @@ FltError ImportLotus::Read()
 	{
 		*pIn >> nOp >> nRecLen;
 
-		if( pIn->IsEof() )
+		if( pIn->IsEof() || nNextRec > SAL_MAX_UINT32 - nRecLen - 4 )
 			eAkt = S_END;
 
 		nNextRec += nRecLen + 4;
@@ -168,18 +168,26 @@ FltError ImportLotus::Read()
 				break;
 
 				case 0x001b:							// extended attributes
-				Read( nSubType );
-				nRecLen -= 2;
-				switch( nSubType )
-				{
-					case 2007:								// ROW PRESENTATION
-					RowPresentation( nRecLen );
-					break;
-
-					case 14000:								// NAMED SHEET
-					NamedSheet();
-					break;
-				}
+                if (nRecLen > 2)
+                {
+                    Read( nSubType );
+                    nRecLen -= 2;
+                    switch( nSubType )
+                    {
+                        case 2007:                      // ROW PRESENTATION
+                            RowPresentation( nRecLen );
+                            break;
+
+                        case 14000:                     // NAMED SHEET
+                            NamedSheet();
+                            break;
+                    }
+                }
+                else
+                {
+                    eRet = eERR_FORMAT;
+                    eAkt = S_END;
+                }
 			}
 
 			break;
@@ -189,12 +197,6 @@ FltError ImportLotus::Read()
 			// -----------------------------------------------------------
 			case S_END:												// S_END
 			break;
-			// -----------------------------------------------------------
-#ifdef DBG_UTIL
-			default:
-			DBG_ERROR( "*ImportLotus::Read(): State unbekannt!" );
-			eAkt = S_END;
-#endif
 		}
 
 		DBG_ASSERT( nNextRec >= pIn->Tell(),
@@ -259,7 +261,7 @@ FltError ImportLotus::Read( SvStream& rI
 	{
 		*pIn >> nOp >> nRecLen;
 
-		if( pIn->IsEof() )
+		if( pIn->IsEof() || nNextRec > SAL_MAX_UINT32 - nRecLen - 4 )
 			bRead = sal_False;
 		else
 		{

Modified: incubator/ooo/trunk/main/sc/source/filter/lotus/memory.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sc/source/filter/lotus/memory.cxx?rev=1362886&r1=1362885&r2=1362886&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sc/source/filter/lotus/memory.cxx (original)
+++ incubator/ooo/trunk/main/sc/source/filter/lotus/memory.cxx Wed Jul 18 11:26:13 2012
@@ -37,38 +37,10 @@
 #include "decl.h"
 #include "tool.h"
 
-extern const long		nStackSize;
-extern const int		nAnzNRange;
-
 extern ScDocument*		pDoc;
 
-const long				nStackSize = 8L * 1024;		// -> form_xxx.cpp
-const int				nAnzNRange = 2048;			// -> tool_xxx.cpp, max. 2048 Named Ranges
-
-sal_Char*				pPuffer;					// -> flt_xxx.cxx
-sal_Char*				pDummy1;					// -> flt_xxx.cxx, ScanVersion()
-sal_Char*				pDummy2;					// -> tool.cxx, CreateTable()
-
-extern sal_uInt8*			pFormelBuffer;				// -> tool.cxx, fuer OP_Formula()
-sal_uInt8*					pFormelBuffer;
-
 extern FormCache*		pValueFormCache;			// -> tool.cxx
 
-sal_Char*				pStack;						// -> formel.cxx
-sal_Char*				pPuffer0;					// -> formel.cxx
-sal_Char*				pPuffer1;					// -> formel.cxx
-extern const int		nMaxPar;
-const int				nMaxPar = 128;				// max. 128 Parameter werden unterstuetzt
-sal_Char**				pPar;						// -> formel.cxx, Pn()
-
-#ifndef _DOS										// -> op.cxx
-sal_Char*				pAnsi;
-#endif
-sal_Char*				pErgebnis;					// -> op.cxx
-
-extern sal_Bool				bFormInit;					// -> tool.cxx, fuer GetFormHandle()
-sal_Bool					bFormInit;
-
 extern SvxHorJustifyItem	*pAttrRight, *pAttrLeft, *pAttrCenter,
 							*pAttrRepeat, *pAttrStandard;	// -> tool.cxx, fuer GetFormAttr()
 extern ScProtectionAttr*	pAttrUnprot;   // -> tool.cxx, fuer PutFormString()
@@ -77,25 +49,6 @@ extern ScProtectionAttr*	pAttrUnprot;   
 
 sal_Bool MemNew( void )
 {
-	pPuffer = new sal_Char [ 32L*1024L ];
-
-	pDummy1 = new sal_Char [ 32 ];
-
-	pDummy2 = new sal_Char [ 32 ];
-
-	pStack = new sal_Char [ nStackSize * 3 ];   // alle drei auf einmal
-
-	pPuffer0 = pStack + nStackSize;
-	pPuffer1 = pPuffer0 + nStackSize;
-
-	pAnsi = new sal_Char [ 2048 ];
-
-	pErgebnis = new sal_Char [ 32L*1024L ];
-
-	pPar = new sal_Char *[ nMaxPar ];
-
-	pFormelBuffer = new sal_uInt8[ 4096 ];
-
 	pValueFormCache = new FormCache( pDoc );
 
 	// fuer tool.cxx::PutFormString()
@@ -105,7 +58,6 @@ sal_Bool MemNew( void )
     pAttrCenter = new SvxHorJustifyItem( SVX_HOR_JUSTIFY_CENTER, ATTR_HOR_JUSTIFY );
     pAttrRepeat = new SvxHorJustifyItem( SVX_HOR_JUSTIFY_REPEAT, ATTR_HOR_JUSTIFY );
     pAttrStandard = new SvxHorJustifyItem( SVX_HOR_JUSTIFY_STANDARD, ATTR_HOR_JUSTIFY );
-	bFormInit = sal_True;
 
 	return sal_True;
 }
@@ -113,15 +65,6 @@ sal_Bool MemNew( void )
 
 void MemDelete( void )
 {
-	delete[] pPuffer;
-	delete[] pDummy1;
-	delete[] pDummy2;
-	delete[] pStack;
-	delete[] pAnsi;
-	delete[] pErgebnis;
-	delete[] pPar;
-	delete[] pFormelBuffer;
-
 	delete pValueFormCache;
 	delete pAttrRight;
 	delete pAttrLeft;

Modified: incubator/ooo/trunk/main/sc/source/filter/lotus/op.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sc/source/filter/lotus/op.cxx?rev=1362886&r1=1362885&r2=1362886&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sc/source/filter/lotus/op.cxx (original)
+++ incubator/ooo/trunk/main/sc/source/filter/lotus/op.cxx Wed Jul 18 11:26:13 2012
@@ -33,9 +33,7 @@
 #include <string.h>
 #include <math.h>
 #include <ctype.h>
-#if defined( ICC )
 #include <stdlib.h>
-#endif
 
 #include "scitems.hxx"
 #include "patattr.hxx"
@@ -53,7 +51,6 @@
 #include "op.h"
 #include "optab.h"
 #include "tool.h"
-//#include "math.h"
 #include "decl.h"
 #include "lotform.hxx"
 #include "lotrange.hxx"
@@ -65,23 +62,10 @@
 #include <vector>
 #include <map>
 
-#include <stdio.h>
-#include <string.h>
-#include <math.h>
-#include <ctype.h>
-#if defined( ICC )
-#include <stdlib.h>
-#endif
-
-extern sal_Char*	pAnsi;			// -> memory.cxx, Puffer zum Umwandeln von OEM->ANSI
-extern sal_Char*	pErgebnis;		// -> memory.cxx, Ergebnispuffer
 extern WKTYP		eTyp;			// -> filter.cxx, aktueller Dateityp
 extern sal_Bool			bEOF;			// -> filter.cxx, zeigt Dateiende an
-extern sal_Char*	pPuffer0;		// -> memory.cxx
-extern sal_Char*	pPuffer1;
 extern sal_uInt8			nDefaultFormat;	// -> tool.cxx, Default-Zellenformat
 extern ScDocument*	pDoc;			// -> filter.cxx, Aufhaenger zum Dokumentzugriff
-extern sal_uInt8*		pFormelBuffer;	// -> memory.cxx, fuer
 extern CharSet		eCharVon;       // -> filter.cxx, character set specified
 
 static sal_uInt16		nDefWidth = ( sal_uInt16 ) ( TWIPS_PER_CHAR * 10 );
@@ -115,11 +99,14 @@ void OP_Integer( SvStream& r, sal_uInt16
 
 	r >> nFormat >> nCol >> nRow >> nValue;
 
-	ScValueCell*	pZelle = new ScValueCell( ( double ) nValue );
-	pDoc->PutCell( static_cast<SCCOL> (nCol), static_cast<SCROW> (nRow), nTab, pZelle, ( sal_Bool ) sal_True );
+    if (ValidColRow( static_cast<SCCOL>(nCol), nRow))
+    {
+        ScValueCell*	pZelle = new ScValueCell( ( double ) nValue );
+        pDoc->PutCell( static_cast<SCCOL> (nCol), static_cast<SCROW> (nRow), nTab, pZelle, ( sal_Bool ) sal_True );
 
-	// 0 Stellen nach'm Komma!
-	SetFormat( static_cast<SCCOL> (nCol), static_cast<SCROW> (nRow), nTab, nFormat, 0 );
+        // 0 Stellen nach'm Komma!
+        SetFormat( static_cast<SCCOL> (nCol), static_cast<SCROW> (nRow), nTab, nFormat, 0 );
+    }
 }
 
 
@@ -132,11 +119,14 @@ void OP_Number( SvStream& r, sal_uInt16 
 
 	r >> nFormat >> nCol >> nRow >> fValue;
 
-	fValue = ::rtl::math::round( fValue, 15 );
-	ScValueCell*	pZelle = new ScValueCell( fValue );
-	pDoc->PutCell( static_cast<SCCOL> (nCol), static_cast<SCROW> (nRow), nTab, pZelle, ( sal_Bool ) sal_True );
+    if (ValidColRow( static_cast<SCCOL>(nCol), nRow))
+    {
+        fValue = ::rtl::math::round( fValue, 15 );
+        ScValueCell*	pZelle = new ScValueCell( fValue );
+        pDoc->PutCell( static_cast<SCCOL> (nCol), static_cast<SCROW> (nRow), nTab, pZelle, ( sal_Bool ) sal_True );
 
-	SetFormat( static_cast<SCCOL> (nCol), static_cast<SCROW> (nRow), nTab, nFormat, nDezFloat );
+        SetFormat( static_cast<SCCOL> (nCol), static_cast<SCROW> (nRow), nTab, nFormat, nDezFloat );
+    }
 }
 
 
@@ -147,37 +137,25 @@ void OP_Label( SvStream& r, sal_uInt16 n
 	SCTAB			nTab = 0;
 
 	r >> nFormat >> nCol >> nRow;
-	n -= 5;
 
- 	sal_Char* pText = new sal_Char[n + 1];
-  	r.Read( pText, n );
- 	pText[n] = 0;
+    n -= (n > 5) ? 5 : n;
 
-	nFormat &= 0x80;    // Bit 7 belassen
-	nFormat |= 0x75;    // protected egal, special-text gesetzt
-
-	PutFormString( static_cast<SCCOL> (nCol), static_cast<SCROW> (nRow), nTab, pText );
+    sal_Char* pText = new sal_Char[n + 1];
+    r.Read( pText, n );
+    pText[n] = 0;
 
-	SetFormat( static_cast<SCCOL> (nCol), static_cast<SCROW> (nRow), nTab, nFormat, nDezStd );
+    if (ValidColRow( static_cast<SCCOL>(nCol), nRow))
+    {
+        nFormat &= 0x80;    // Bit 7 belassen
+        nFormat |= 0x75;    // protected egal, special-text gesetzt
 
-	delete [] pText;
-}
+        PutFormString( static_cast<SCCOL> (nCol), static_cast<SCROW> (nRow), nTab, pText );
 
+        SetFormat( static_cast<SCCOL> (nCol), static_cast<SCROW> (nRow), nTab, nFormat, nDezStd );
+    }
 
-//UNUSED2009-05 void OP_Text( SvStream& r, sal_uInt16 n )        // WK3
-//UNUSED2009-05 {
-//UNUSED2009-05     sal_uInt16          nRow;
-//UNUSED2009-05     sal_uInt8            nCol, nTab;
-//UNUSED2009-05     sal_Char        pText[ 256 ];
-//UNUSED2009-05 
-//UNUSED2009-05     r >> nRow >> nTab >> nCol;
-//UNUSED2009-05     n -= 4;
-//UNUSED2009-05 
-//UNUSED2009-05     r.Read( pText, n );
-//UNUSED2009-05     pText[ n ] = 0;   // zur Sicherheit Nullterminator anhaengen
-//UNUSED2009-05 
-//UNUSED2009-05     PutFormString( static_cast<SCCOL> (nCol), static_cast<SCROW> (nRow), static_cast<SCTAB> (nTab), pText );
-//UNUSED2009-05 }
+    delete [] pText;
+}
 
 
 void OP_Formula( SvStream& r, sal_uInt16 /*n*/ )
@@ -198,14 +176,17 @@ void OP_Formula( SvStream& r, sal_uInt16
 	aConv.Reset( aAddress );
 	aConv.Convert( pErg, nBytesLeft );
 
-	ScFormulaCell*		pZelle = new ScFormulaCell( pLotusRoot->pDoc, aAddress, pErg );
+    if (ValidColRow( static_cast<SCCOL>(nCol), nRow))
+    {
+        ScFormulaCell*		pZelle = new ScFormulaCell( pLotusRoot->pDoc, aAddress, pErg );
 
-	pZelle->AddRecalcMode( RECALCMODE_ONLOAD_ONCE );
+        pZelle->AddRecalcMode( RECALCMODE_ONLOAD_ONCE );
 
-	pDoc->PutCell( static_cast<SCCOL> (nCol), static_cast<SCROW> (nRow), nTab, pZelle, ( sal_Bool ) sal_True );
+        pDoc->PutCell( static_cast<SCCOL> (nCol), static_cast<SCROW> (nRow), nTab, pZelle, ( sal_Bool ) sal_True );
 
-	// nFormat = Standard -> Nachkommastellen wie Float
-	SetFormat( static_cast<SCCOL> (nCol), static_cast<SCROW> (nRow), nTab, nFormat, nDezFloat );
+        // nFormat = Standard -> Nachkommastellen wie Float
+        SetFormat( static_cast<SCCOL> (nCol), static_cast<SCROW> (nRow), nTab, nFormat, nDezFloat );
+    }
 }
 
 
@@ -217,16 +198,19 @@ void OP_ColumnWidth( SvStream& r, sal_uI
 
 	r >> nCol >> nWidthSpaces;
 
-	if( nWidthSpaces )
-		// Annahme: 10cpi-Zeichensatz
-		nBreite = ( sal_uInt16 ) ( TWIPS_PER_CHAR * nWidthSpaces );
-	else
-	{
-        pDoc->SetColHidden(static_cast<SCCOL>(nCol), static_cast<SCCOL>(nCol), 0, true);
-		nBreite = nDefWidth;
-	}
+    if (ValidCol( static_cast<SCCOL>(nCol)))
+    {
+        if( nWidthSpaces )
+            // Annahme: 10cpi-Zeichensatz
+            nBreite = ( sal_uInt16 ) ( TWIPS_PER_CHAR * nWidthSpaces );
+        else
+        {
+            pDoc->SetColHidden(static_cast<SCCOL>(nCol), static_cast<SCCOL>(nCol), 0, true);
+            nBreite = nDefWidth;
+        }
 
-	pDoc->SetColWidth( static_cast<SCCOL> (nCol), nTab, nBreite );
+        pDoc->SetColWidth( static_cast<SCCOL> (nCol), nTab, nBreite );
+    }
 }
 
 
@@ -234,32 +218,38 @@ void OP_NamedRange( SvStream& r, sal_uIn
 	{
 	// POST:    waren Koordinaten ungueltig, wird nicht gespeichert
 	sal_uInt16				nColSt, nRowSt, nColEnd, nRowEnd;
-	sal_Char			cPuffer[ 32 ];
 
+    sal_Char cPuffer[ 16+1 ];
 	r.Read( cPuffer, 16 );
+	cPuffer[ 16 ] = 0;
 
 	r >> nColSt >> nRowSt >> nColEnd >> nRowEnd;
 
-	LotusRange*			pRange;
+    if (ValidColRow( static_cast<SCCOL>(nColSt), nRowSt) && ValidColRow( static_cast<SCCOL>(nColEnd), nRowEnd))
+    {
+        LotusRange*			pRange;
 
-	if( nColSt == nColEnd && nRowSt == nRowEnd )
-		pRange = new LotusRange( static_cast<SCCOL> (nColSt), static_cast<SCROW> (nRowSt) );
-	else
-		pRange = new LotusRange( static_cast<SCCOL> (nColSt), static_cast<SCROW> (nRowSt), static_cast<SCCOL> (nColEnd), static_cast<SCROW> (nRowEnd) );
-
-	if( isdigit( *cPuffer ) )
-	{	// erstes Zeichen im Namen eine Zahl -> 'A' vor Namen setzen
-		*pAnsi = 'A';
-		strcpy( pAnsi + 1, cPuffer );       // #100211# - checked
-	}
-	else
-		strcpy( pAnsi, cPuffer );           // #100211# - checked
+        if( nColSt == nColEnd && nRowSt == nRowEnd )
+            pRange = new LotusRange( static_cast<SCCOL> (nColSt), static_cast<SCROW> (nRowSt) );
+        else
+            pRange = new LotusRange( static_cast<SCCOL> (nColSt), static_cast<SCROW> (nRowSt),
+                    static_cast<SCCOL> (nColEnd), static_cast<SCROW> (nRowEnd) );
+
+        sal_Char cBuf[sizeof(cPuffer)+1];
+        if( isdigit( *cPuffer ) )
+        {	// erstes Zeichen im Namen eine Zahl -> 'A' vor Namen setzen
+            cBuf[0] = 'A';
+            strcpy( cBuf + 1, cPuffer );       // #100211# - checked
+        }
+        else
+            strcpy( cBuf, cPuffer );           // #100211# - checked
 
-	String				aTmp( pAnsi, pLotusRoot->eCharsetQ );
+        String				aTmp( cBuf, pLotusRoot->eCharsetQ );
 
-    ScfTools::ConvertToScDefinedName( aTmp );
+        ScfTools::ConvertToScDefinedName( aTmp );
 
-	pLotusRoot->pRangeNames->Append( pRange, aTmp );
+        pLotusRoot->pRangeNames->Append( pRange, aTmp );
+    }
 }
 
 
@@ -268,34 +258,37 @@ void OP_SymphNamedRange( SvStream& r, sa
 	// POST:    waren Koordinaten ungueltig, wird nicht gespeichert
 	sal_uInt16				nColSt, nRowSt, nColEnd, nRowEnd;
 	sal_uInt8				nType;
-	sal_Char*			pName;
-	sal_Char			cPuffer[ 32 ];
 
+    sal_Char cPuffer[ 16+1 ];
 	r.Read( cPuffer, 16 );
 	cPuffer[ 16 ] = 0;
-	pName = cPuffer;
 
 	r >> nColSt >> nRowSt >> nColEnd >> nRowEnd >> nType;
 
-	LotusRange*			pRange;
+    if (ValidColRow( static_cast<SCCOL>(nColSt), nRowSt) && ValidColRow( static_cast<SCCOL>(nColEnd), nRowEnd))
+    {
+        LotusRange*			pRange;
 
-	if( nType )
-		pRange = new LotusRange( static_cast<SCCOL> (nColSt), static_cast<SCROW> (nRowSt) );
-	else
-		pRange = new LotusRange( static_cast<SCCOL> (nColSt), static_cast<SCROW> (nRowSt), static_cast<SCCOL> (nColEnd), static_cast<SCROW> (nRowEnd) );
-
-	if( isdigit( *cPuffer ) )
-	{	// erstes Zeichen im Namen eine Zahl -> 'A' vor Namen setzen
-		*pAnsi = 'A';
-		strcpy( pAnsi + 1, cPuffer );       // #100211# - checked
-	}
-	else
-		strcpy( pAnsi, cPuffer );           // #100211# - checked
+        if( nType )
+            pRange = new LotusRange( static_cast<SCCOL> (nColSt), static_cast<SCROW> (nRowSt) );
+        else
+            pRange = new LotusRange( static_cast<SCCOL> (nColSt), static_cast<SCROW> (nRowSt),
+                    static_cast<SCCOL> (nColEnd), static_cast<SCROW> (nRowEnd) );
+
+        sal_Char cBuf[sizeof(cPuffer)+1];
+        if( isdigit( *cPuffer ) )
+        {	// erstes Zeichen im Namen eine Zahl -> 'A' vor Namen setzen
+            cBuf[0] = 'A';
+            strcpy( cBuf + 1, cPuffer );       // #100211# - checked
+        }
+        else
+            strcpy( cBuf, cPuffer );           // #100211# - checked
 
-	String		aTmp( pAnsi, pLotusRoot->eCharsetQ );
-    ScfTools::ConvertToScDefinedName( aTmp );
+        String		aTmp( cBuf, pLotusRoot->eCharsetQ );
+        ScfTools::ConvertToScDefinedName( aTmp );
 
-	pLotusRoot->pRangeNames->Append( pRange, aTmp );
+        pLotusRoot->pRangeNames->Append( pRange, aTmp );
+    }
 }
 
 
@@ -385,7 +378,7 @@ void OP_Label123( SvStream& r, sal_uInt1
 	sal_uInt8      nTab, nCol;
 	sal_uInt16    nRow;
 	r >> nRow >> nTab >> nCol;
-	n -= 4;
+    n -= (n > 4) ? 4 : n;
 
 	sal_Char* pText = new sal_Char[n + 1];
 	r.Read( pText, n );
@@ -403,10 +396,14 @@ void OP_Number123( SvStream& r, sal_uInt
 	sal_uInt32   nValue;
 
 	r >> nRow >> nTab >> nCol >> nValue;
-	double fValue = Snum32ToDouble( nValue );
 
-	ScValueCell *pCell = new ScValueCell( fValue );
-	pDoc->PutCell( static_cast<SCCOL>(nCol), static_cast<SCROW>(nRow), static_cast<SCTAB>(nTab), pCell, (sal_Bool) sal_True );
+    if (ValidColRow( static_cast<SCCOL>(nCol), nRow) && nTab < pDoc->GetMaxTableNumber())
+    {
+        double fValue = Snum32ToDouble( nValue );
+
+        ScValueCell *pCell = new ScValueCell( fValue );
+        pDoc->PutCell( static_cast<SCCOL>(nCol), static_cast<SCROW>(nRow), static_cast<SCTAB>(nTab), pCell, (sal_Bool) sal_True );
+    }
 }
 
 void OP_Formula123( SvStream& r, sal_uInt16 n )
@@ -418,18 +415,21 @@ void OP_Formula123( SvStream& r, sal_uIn
     r.SeekRel( 8 );    // Result- jump over
 
     const ScTokenArray*	pErg;
-    sal_Int32				nBytesLeft = n - 12;
+    sal_Int32				nBytesLeft = (n > 12) ? n - 12 : 0;
     ScAddress			aAddress( nCol, nRow, nTab );
 
     LotusToSc			aConv( r, pLotusRoot->eCharsetQ, sal_True );
     aConv.Reset( aAddress );
     aConv.Convert( pErg, nBytesLeft );
 
-    ScFormulaCell*		pCell = new ScFormulaCell( pLotusRoot->pDoc, aAddress, pErg );
+    if (ValidColRow( static_cast<SCCOL>(nCol), nRow) && nTab < pDoc->GetMaxTableNumber())
+    {
+        ScFormulaCell*		pCell = new ScFormulaCell( pLotusRoot->pDoc, aAddress, pErg );
 
-    pCell->AddRecalcMode( RECALCMODE_ONLOAD_ONCE );
+        pCell->AddRecalcMode( RECALCMODE_ONLOAD_ONCE );
 
-    pDoc->PutCell( static_cast<SCCOL>(nCol), static_cast<SCROW>(nRow), static_cast<SCTAB>(nTab), pCell, (sal_Bool) sal_True );
+        pDoc->PutCell( static_cast<SCCOL>(nCol), static_cast<SCROW>(nRow), static_cast<SCTAB>(nTab), pCell, (sal_Bool) sal_True );
+    }
 }
 
 void OP_IEEENumber123( SvStream& r, sal_uInt16 /*n*/ )
@@ -440,8 +440,11 @@ void OP_IEEENumber123( SvStream& r, sal_
 
     r >> nRow >> nTab >> nCol >> dValue;
 
-    ScValueCell *pCell = new ScValueCell(dValue);
-    pDoc->PutCell( static_cast<SCCOL>(nCol), static_cast<SCROW>(nRow), static_cast<SCTAB>(nTab), pCell, (sal_Bool) sal_True );
+    if (ValidColRow( static_cast<SCCOL>(nCol), nRow) && nTab < pDoc->GetMaxTableNumber())
+    {
+        ScValueCell *pCell = new ScValueCell(dValue);
+        pDoc->PutCell( static_cast<SCCOL>(nCol), static_cast<SCROW>(nRow), static_cast<SCTAB>(nTab), pCell, (sal_Bool) sal_True );
+    }
 }
 
 void OP_Note123( SvStream& r, sal_uInt16 n)
@@ -449,7 +452,7 @@ void OP_Note123( SvStream& r, sal_uInt16
     sal_uInt8      nTab, nCol;
     sal_uInt16    nRow;
     r >> nRow >> nTab >> nCol;
-    n -= 4;
+    n -= (n > 4) ? 4 : n;
 
     sal_Char* pText = new sal_Char[n + 1];
     r.Read( pText, n );
@@ -532,7 +535,7 @@ void OP_CreatePattern123( SvStream& r, s
     SfxItemSet& rItemSet = aPattern.GetItemSet();
 
     r >> nCode;
-    n = n - 2;
+    n -= (n > 2) ? 2 : n;
 
     if ( nCode == 0x0fd2 )
     {
@@ -567,7 +570,7 @@ void OP_CreatePattern123( SvStream& r, s
         OP_VerAlign123( Ver_Align, rItemSet );
 
         aLotusPatternPool.insert( std::map<sal_uInt16, ScPatternAttr>::value_type( nPatternId, aPattern ) );
-        n = n - 20;
+        n -= (n > 20) ? 20 : n;
     }
     r.SeekRel(n);
 }
@@ -656,15 +659,13 @@ void OP_ApplyPatternArea123( SvStream& r
                 {
                     rStream >> nData;
                     rStream.SeekRel( nLength - 2 );
-                    for( int i = 0; i < nTabCount; i++)
-                    {
-                        std::map<sal_uInt16, ScPatternAttr>::iterator loc = aLotusPatternPool.find( nData );
-
-                        // #126338# apparently, files with invalid index occur in the wild -> don't crash then
-                        DBG_ASSERT( loc != aLotusPatternPool.end(), "invalid format index" );
-                        if ( loc != aLotusPatternPool.end() )
+                    std::map<sal_uInt16, ScPatternAttr>::iterator loc = aLotusPatternPool.find( nData );
+                    // #126338# apparently, files with invalid index occur in the wild -> don't crash then
+                    if ( loc != aLotusPatternPool.end() )
+                        for( int i = 0; i < nTabCount; i++)
+                        {
                             pDoc->ApplyPatternAreaTab( nCol, nRow, nCol +  nColCount - 1, nRow + nRowCount - 1, static_cast< SCTAB >( nTab + i ), loc->second );
-                    }
+                        }
                 }
                 else
                     rStream.SeekRel( nLength );

Modified: incubator/ooo/trunk/main/sc/source/filter/lotus/tool.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sc/source/filter/lotus/tool.cxx?rev=1362886&r1=1362885&r2=1362886&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sc/source/filter/lotus/tool.cxx (original)
+++ incubator/ooo/trunk/main/sc/source/filter/lotus/tool.cxx Wed Jul 18 11:26:13 2012
@@ -52,11 +52,7 @@
 
 //--------------------------------------------------------- EXTERNE VARIABLEN -
 extern WKTYP				eTyp;			// -> filter.cxx, aktueller Dateityp
-extern sal_Char*			pDummy2;		// -> memory.cxx
 extern ScDocument*			pDoc;			// -> filter.cxx, Aufhaenger zum Dokumentzugriff
-extern CharSet				eCharNach;		// -> filter.cxx, Zeichenkonvertierung von->nach
-
-extern sal_Bool					bFormInit;		// -> memory.cxx, fuer GetFormHandle()
 
 //--------------------------------------------------------- GLOBALE VARIABLEN -
 sal_uInt8						nDefaultFormat;	// -> op.cpp, Standard-Zellenformat
@@ -82,6 +78,8 @@ void PutFormString( SCCOL nCol, SCROW nR
 {
 	// Label-Format-Auswertung
 	DBG_ASSERT( pString != NULL, "PutFormString(): pString == NULL" );
+    if (!pString)
+        return;
 
 	sal_Char			cForm;
 	SvxHorJustifyItem*	pJustify = NULL;
@@ -113,12 +111,9 @@ void PutFormString( SCCOL nCol, SCROW nR
 			pJustify = pAttrStandard;
 	}
 
-	if( pString )
-	{
-		pDoc->ApplyAttr( nCol, nRow, nTab, *pJustify );
-		ScStringCell*	pZelle = new ScStringCell( String( pString, pLotusRoot->eCharsetQ ) );
-		pDoc->PutCell( nCol, nRow, nTab, pZelle, ( sal_Bool ) sal_True );
-	}
+    pDoc->ApplyAttr( nCol, nRow, nTab, *pJustify );
+    ScStringCell*	pZelle = new ScStringCell( String( pString, pLotusRoot->eCharsetQ ) );
+    pDoc->PutCell( nCol, nRow, nTab, pZelle, ( sal_Bool ) sal_True );
 }
 
 



Mime
View raw message