You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openoffice.apache.org by or...@apache.org on 2012/08/20 13:46:47 UTC

svn commit: r1374979 [22/29] - in /incubator/ooo/branches/writer001: ./ ext_libraries/apr-util/ ext_libraries/apr-util/prj/ ext_libraries/apr/ ext_libraries/coinmp/ ext_libraries/hunspell/ ext_libraries/serf/ ext_libraries/serf/prj/ ext_sources/ extras...

Modified: incubator/ooo/branches/writer001/main/sc/source/filter/lotus/lotform.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/branches/writer001/main/sc/source/filter/lotus/lotform.cxx?rev=1374979&r1=1374978&r2=1374979&view=diff
==============================================================================
--- incubator/ooo/branches/writer001/main/sc/source/filter/lotus/lotform.cxx (original)
+++ incubator/ooo/branches/writer001/main/sc/source/filter/lotus/lotform.cxx Mon Aug 20 11:46:19 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/branches/writer001/main/sc/source/filter/lotus/lotimpop.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/branches/writer001/main/sc/source/filter/lotus/lotimpop.cxx?rev=1374979&r1=1374978&r2=1374979&view=diff
==============================================================================
--- incubator/ooo/branches/writer001/main/sc/source/filter/lotus/lotimpop.cxx (original)
+++ incubator/ooo/branches/writer001/main/sc/source/filter/lotus/lotimpop.cxx Mon Aug 20 11:46:19 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/branches/writer001/main/sc/source/filter/lotus/lotread.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/branches/writer001/main/sc/source/filter/lotus/lotread.cxx?rev=1374979&r1=1374978&r2=1374979&view=diff
==============================================================================
--- incubator/ooo/branches/writer001/main/sc/source/filter/lotus/lotread.cxx (original)
+++ incubator/ooo/branches/writer001/main/sc/source/filter/lotus/lotread.cxx Mon Aug 20 11:46:19 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/branches/writer001/main/sc/source/filter/lotus/memory.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/branches/writer001/main/sc/source/filter/lotus/memory.cxx?rev=1374979&r1=1374978&r2=1374979&view=diff
==============================================================================
--- incubator/ooo/branches/writer001/main/sc/source/filter/lotus/memory.cxx (original)
+++ incubator/ooo/branches/writer001/main/sc/source/filter/lotus/memory.cxx Mon Aug 20 11:46:19 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/branches/writer001/main/sc/source/filter/lotus/op.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/branches/writer001/main/sc/source/filter/lotus/op.cxx?rev=1374979&r1=1374978&r2=1374979&view=diff
==============================================================================
--- incubator/ooo/branches/writer001/main/sc/source/filter/lotus/op.cxx (original)
+++ incubator/ooo/branches/writer001/main/sc/source/filter/lotus/op.cxx Mon Aug 20 11:46:19 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/branches/writer001/main/sc/source/filter/lotus/tool.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/branches/writer001/main/sc/source/filter/lotus/tool.cxx?rev=1374979&r1=1374978&r2=1374979&view=diff
==============================================================================
--- incubator/ooo/branches/writer001/main/sc/source/filter/lotus/tool.cxx (original)
+++ incubator/ooo/branches/writer001/main/sc/source/filter/lotus/tool.cxx Mon Aug 20 11:46:19 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 );
 }
 
 

Modified: incubator/ooo/branches/writer001/main/sc/source/filter/qpro/qpro.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/branches/writer001/main/sc/source/filter/qpro/qpro.cxx?rev=1374979&r1=1374978&r2=1374979&view=diff
==============================================================================
--- incubator/ooo/branches/writer001/main/sc/source/filter/qpro/qpro.cxx (original)
+++ incubator/ooo/branches/writer001/main/sc/source/filter/qpro/qpro.cxx Mon Aug 20 11:46:19 2012
@@ -61,10 +61,16 @@ FltError ScQProReader::readSheet( SCTAB 
             case 0x000f:{ // Label cell
                 String aLabel;
                 *mpStream >> nCol >> nDummy >> nRow >> nStyle >> nDummy;
-                readString( aLabel, getLength() - 7 );
-                nStyle = nStyle >> 3;
-                pStyle->SetFormat( pDoc, nCol, nRow, nTab, nStyle );
-                pDoc->PutCell( nCol, nRow, nTab, ScBaseCell::CreateTextCell( aLabel, pDoc ), (sal_Bool) sal_True );
+                sal_uInt16 nLen = getLength();
+                if (nLen >= 7)
+                {
+                    readString( aLabel, nLen - 7 );
+                    nStyle = nStyle >> 3;
+                    pStyle->SetFormat( pDoc, nCol, nRow, nTab, nStyle );
+                    pDoc->PutCell( nCol, nRow, nTab, ScBaseCell::CreateTextCell( aLabel, pDoc ), (sal_Bool) sal_True );
+                }
+                else
+                    eRet = eERR_FORMAT;
                 }
                 break;
 
@@ -192,7 +198,11 @@ FltError ScQProReader::import( ScDocumen
                 String aLabel;
                 *mpStream >> nPtSize >> nFontAttr;
                 pStyleElement->setFontRecord( j, nFontAttr, nPtSize );
-                readString( aLabel, getLength() - 4 );
+                sal_uInt16 nLen = getLength();
+                if (nLen >= 4)
+                    readString( aLabel, nLen - 4 );
+                else
+                    eRet = eERR_FORMAT;
                 pStyleElement->setFontType( j, aLabel );
                 j++;
                 }

Modified: incubator/ooo/branches/writer001/main/sc/source/filter/starcalc/scflt.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/branches/writer001/main/sc/source/filter/starcalc/scflt.cxx?rev=1374979&r1=1374978&r2=1374979&view=diff
==============================================================================
--- incubator/ooo/branches/writer001/main/sc/source/filter/starcalc/scflt.cxx (original)
+++ incubator/ooo/branches/writer001/main/sc/source/filter/starcalc/scflt.cxx Mon Aug 20 11:46:19 2012
@@ -82,36 +82,51 @@ using namespace com::sun::star;
 
 #define	DEFCHARSET			RTL_TEXTENCODING_MS_1252
 
-#define SC10TOSTRING(p)		String(p,DEFCHARSET)
+#define SC10TOSTRING(p)		String((p),DEFCHARSET)
 
 const SCCOL SC10MAXCOL = 255;   // #i85906# don't try to load more columns than there are in the file
 
 
-void lcl_ReadFileHeader(SvStream& rStream, Sc10FileHeader& rFileHeader)
+/** Those strings are used with SC10TOSTRING() and strcmp() and such, hence 
+    need to be 0-terminated. */
+static void lcl_ReadFixedString( SvStream& rStream, void* pData, size_t nLen )
 {
-	rStream.Read(&rFileHeader.CopyRight, sizeof(rFileHeader.CopyRight));
+    sal_Char* pBuf = static_cast<sal_Char*>(pData);
+    if (!nLen)
+        pBuf[0] = 0;
+    else
+    {
+        rStream.Read( pBuf, nLen);
+        pBuf[nLen-1] = 0;
+    }
+}
+
+
+static void lcl_ReadFileHeader(SvStream& rStream, Sc10FileHeader& rFileHeader)
+{
+	lcl_ReadFixedString( rStream, &rFileHeader.CopyRight, sizeof(rFileHeader.CopyRight));
 	rStream >> rFileHeader.Version;
 	rStream.Read(&rFileHeader.Reserved, sizeof(rFileHeader.Reserved));
 }
 
 
-void lcl_ReadTabProtect(SvStream& rStream, Sc10TableProtect& rProtect)
+static void lcl_ReadTabProtect(SvStream& rStream, Sc10TableProtect& rProtect)
 {
-	rStream.Read(&rProtect.PassWord, sizeof(rProtect.PassWord));
+	lcl_ReadFixedString( rStream, &rProtect.PassWord, sizeof(rProtect.PassWord));
 	rStream >> rProtect.Flags;
 	rStream >> rProtect.Protect;
 }
 
 
-void lcl_ReadSheetProtect(SvStream& rStream, Sc10SheetProtect& rProtect)
+static void lcl_ReadSheetProtect(SvStream& rStream, Sc10SheetProtect& rProtect)
 {
-	rStream.Read(&rProtect.PassWord, sizeof(rProtect.PassWord));
+	lcl_ReadFixedString( rStream, &rProtect.PassWord, sizeof(rProtect.PassWord));
 	rStream >> rProtect.Flags;
 	rStream >> rProtect.Protect;
 }
 
 
-void lcl_ReadRGB(SvStream& rStream, Sc10Color& rColor)
+static void lcl_ReadRGB(SvStream& rStream, Sc10Color& rColor)
 {
 	rStream >> rColor.Dummy;
 	rStream >> rColor.Blue;
@@ -120,21 +135,21 @@ void lcl_ReadRGB(SvStream& rStream, Sc10
 }
 
 
-void lcl_ReadPalette(SvStream& rStream, Sc10Color* pPalette)
+static void lcl_ReadPalette(SvStream& rStream, Sc10Color* pPalette)
 {
 	for (sal_uInt16 i = 0; i < 16; i++)
 		lcl_ReadRGB(rStream, pPalette[i]);
 }
 
 
-void lcl_ReadValueFormat(SvStream& rStream, Sc10ValueFormat& rFormat)
+static void lcl_ReadValueFormat(SvStream& rStream, Sc10ValueFormat& rFormat)
 {
 	rStream >> rFormat.Format;
 	rStream >> rFormat.Info;
 }
 
 
-void lcl_ReadLogFont(SvStream& rStream, Sc10LogFont& rFont)
+static void lcl_ReadLogFont(SvStream& rStream, Sc10LogFont& rFont)
 {
 	rStream >> rFont.lfHeight;
 	rStream >> rFont.lfWidth;
@@ -149,11 +164,11 @@ void lcl_ReadLogFont(SvStream& rStream, 
 	rStream >> rFont.lfClipPrecision;
 	rStream >> rFont.lfQuality;
 	rStream >> rFont.lfPitchAndFamily;
-	rStream.Read(&rFont.lfFaceName, sizeof(rFont.lfFaceName));
+	lcl_ReadFixedString( rStream, &rFont.lfFaceName, sizeof(rFont.lfFaceName));
 }
 
 
-void lcl_ReadBlockRect(SvStream& rStream, Sc10BlockRect& rBlock)
+static void lcl_ReadBlockRect(SvStream& rStream, Sc10BlockRect& rBlock)
 {
 	rStream >> rBlock.x1;
 	rStream >> rBlock.y1;
@@ -162,9 +177,9 @@ void lcl_ReadBlockRect(SvStream& rStream
 }
 
 
-void lcl_ReadHeadFootLine(SvStream& rStream, Sc10HeadFootLine& rLine)
+static void lcl_ReadHeadFootLine(SvStream& rStream, Sc10HeadFootLine& rLine)
 {
-	rStream.Read(&rLine.Title, sizeof(rLine.Title));
+	lcl_ReadFixedString( rStream, &rLine.Title, sizeof(rLine.Title));
 	lcl_ReadLogFont(rStream, rLine.LogFont);
 	rStream >> rLine.HorJustify;
 	rStream >> rLine.VerJustify;
@@ -178,7 +193,7 @@ void lcl_ReadHeadFootLine(SvStream& rStr
 }
 
 
-void lcl_ReadPageFormat(SvStream& rStream, Sc10PageFormat& rFormat)
+static void lcl_ReadPageFormat(SvStream& rStream, Sc10PageFormat& rFormat)
 {
 	lcl_ReadHeadFootLine(rStream, rFormat.HeadLine);
 	lcl_ReadHeadFootLine(rStream, rFormat.FootLine);
@@ -199,7 +214,7 @@ void lcl_ReadPageFormat(SvStream& rStrea
 	rStream >> rFormat.PrintColRow;
 	rStream >> rFormat.PrintNote;
 	rStream >> rFormat.TopBottomDir;
-	rStream.Read(&rFormat.PrintAreaName, sizeof(rFormat.PrintAreaName));
+	lcl_ReadFixedString( rStream, &rFormat.PrintAreaName, sizeof(rFormat.PrintAreaName));
 	lcl_ReadBlockRect(rStream, rFormat.PrintArea);
 	rStream.Read(&rFormat.PrnZoom, sizeof(rFormat.PrnZoom));
 	rStream >> rFormat.FirstPageNo;
@@ -211,7 +226,7 @@ void lcl_ReadPageFormat(SvStream& rStrea
 }
 
 
-void lcl_ReadGraphHeader(SvStream& rStream, Sc10GraphHeader& rHeader)
+static void lcl_ReadGraphHeader(SvStream& rStream, Sc10GraphHeader& rHeader)
 {
 	rStream >> rHeader.Typ;
 	rStream >> rHeader.CarretX;
@@ -231,9 +246,9 @@ void lcl_ReadGraphHeader(SvStream& rStre
 }
 
 
-void lcl_ReadImageHeaer(SvStream& rStream, Sc10ImageHeader& rHeader)
+static void lcl_ReadImageHeaer(SvStream& rStream, Sc10ImageHeader& rHeader)
 {
-	rStream.Read(&rHeader.FileName, sizeof(rHeader.FileName));
+	lcl_ReadFixedString( rStream, &rHeader.FileName, sizeof(rHeader.FileName));
 	rStream >> rHeader.Typ;
 	rStream >> rHeader.Linked;
 	rStream >> rHeader.x1;
@@ -244,7 +259,7 @@ void lcl_ReadImageHeaer(SvStream& rStrea
 }
 
 
-void lcl_ReadChartHeader(SvStream& rStream, Sc10ChartHeader& rHeader)
+static void lcl_ReadChartHeader(SvStream& rStream, Sc10ChartHeader& rHeader)
 {
 	rStream >> rHeader.MM;
 	rStream >> rHeader.xExt;
@@ -253,7 +268,7 @@ void lcl_ReadChartHeader(SvStream& rStre
 }
 
 
-void lcl_ReadChartSheetData(SvStream& rStream, Sc10ChartSheetData& rSheetData)
+static void lcl_ReadChartSheetData(SvStream& rStream, Sc10ChartSheetData& rSheetData)
 {
 	rStream >> rSheetData.HasTitle;
 	rStream >> rSheetData.TitleX;
@@ -282,15 +297,15 @@ void lcl_ReadChartSheetData(SvStream& rS
 }
 
 
-void lcl_ReadChartTypeData(SvStream& rStream, Sc10ChartTypeData& rTypeData)
+static void lcl_ReadChartTypeData(SvStream& rStream, Sc10ChartTypeData& rTypeData)
 {
 	rStream >> rTypeData.NumSets;
 	rStream >> rTypeData.NumPoints;
 	rStream >> rTypeData.DrawMode;
 	rStream >> rTypeData.GraphType;
 	rStream >> rTypeData.GraphStyle;
-	rStream.Read(&rTypeData.GraphTitle, sizeof(rTypeData.GraphTitle));
-	rStream.Read(&rTypeData.BottomTitle, sizeof(rTypeData.BottomTitle));
+	lcl_ReadFixedString( rStream, &rTypeData.GraphTitle, sizeof(rTypeData.GraphTitle));
+	lcl_ReadFixedString( rStream, &rTypeData.BottomTitle, sizeof(rTypeData.BottomTitle));
 	sal_uInt16 i;
 	for (i = 0; i < 256; i++)
 		rStream >> rTypeData.SymbolData[i];
@@ -306,7 +321,7 @@ void lcl_ReadChartTypeData(SvStream& rSt
 		rStream >> rTypeData.NumGraphStyles[i];
 	rStream >> rTypeData.ShowLegend;
 	for (i = 0; i < 256; i++)
-		rStream.Read(&rTypeData.LegendText[i], sizeof(Sc10ChartText));
+		lcl_ReadFixedString( rStream, &rTypeData.LegendText[i], sizeof(Sc10ChartText));
 	rStream >> rTypeData.ExplodePie;
 	rStream >> rTypeData.FontUse;
 	for (i = 0; i < 5; i++)
@@ -319,30 +334,13 @@ void lcl_ReadChartTypeData(SvStream& rSt
 	rStream >> rTypeData.Labels;
 	rStream >> rTypeData.LabelEvery;
 	for (i = 0; i < 50; i++)
-		rStream.Read(&rTypeData.LabelText[i], sizeof(Sc10ChartText));
-	rStream.Read(&rTypeData.LeftTitle, sizeof(rTypeData.LeftTitle));
+		lcl_ReadFixedString( rStream, &rTypeData.LabelText[i], sizeof(Sc10ChartText));
+	lcl_ReadFixedString( rStream, &rTypeData.LeftTitle, sizeof(rTypeData.LeftTitle));
 	rStream.Read(&rTypeData.Reserved, sizeof(rTypeData.Reserved));
-	//rStream.Read(&rTypeData, sizeof(rTypeData));
 }
 
 double lcl_PascalToDouble(sal_Char* tp6)
 {
-// #i68483# bah! this was broken forever...
-//   struct
-//   {
-//        sal_uInt8       be  ;     /* biased exponent           */
-//        sal_uInt16      v1  ;     /* lower 16 bits of mantissa */
-//        sal_uInt16      v2  ;     /* next  16 bits of mantissa */
-//        sal_uInt8       v3:7;     /* upper  7 bits of mantissa */
-//        sal_uInt8       s :1;     /* sign bit                  */
-//   } real;
-//
-//   memcpy (&real, tp6, 6);
-//   if (real.be == 0)
-//         return 0.0;
-//   return (((((128 +real.v3) * 65536.0) + real.v2) * 65536.0 + real.v1) *
-//         ldexp ((real.s? -1.0: 1.0), real.be - (129+39)));
-
     sal_uInt8* pnUnsigned = reinterpret_cast< sal_uInt8* >( tp6 );
     // biased exponent
     sal_uInt8 be = pnUnsigned[ 0 ];
@@ -362,7 +360,7 @@ double lcl_PascalToDouble(sal_Char* tp6)
 }
 
 
-void lcl_ChangeColor( sal_uInt16 nIndex, Color& rColor )
+static void lcl_ChangeColor( sal_uInt16 nIndex, Color& rColor )
 {
 	ColorData aCol;
 
@@ -398,6 +396,23 @@ String lcl_MakeOldPageStyleFormatName( s
 	return aName;
 }
 
+
+template < typename T > sal_uLong insert_new( ScCollection* pCollection, SvStream& rStream )
+{
+    T* pData = new (::std::nothrow) T( rStream);
+    sal_uLong nError = rStream.GetError();
+    if (pData)
+    {
+        if (nError)
+            delete pData;
+        else
+            pCollection->Insert( pData);
+    }
+    else
+        nError = errOutOfMemory;
+    return nError;
+}
+
 //--------------------------------------------
 // Font
 //--------------------------------------------
@@ -429,8 +444,7 @@ Sc10FontCollection::Sc10FontCollection(S
 	rStream >> nAnz;
 	for (sal_uInt16 i=0; (i < nAnz) && (nError == 0); i++)
 	{
-	  Insert(new Sc10FontData(rStream));
-	  nError = rStream.GetError();
+        nError = insert_new<Sc10FontData>( this, rStream);
 	}
   }
   else
@@ -476,8 +490,7 @@ Sc10NameCollection::Sc10NameCollection(S
 	rStream >> nAnz;
 	for (sal_uInt16 i=0; (i < nAnz) && (nError == 0); i++)
 	{
-	  Insert(new Sc10NameData(rStream));
-	  nError = rStream.GetError();
+        nError = insert_new<Sc10NameData>( this, rStream);
 	}
   }
   else
@@ -494,9 +507,7 @@ Sc10NameCollection::Sc10NameCollection(S
 
 Sc10PatternData::Sc10PatternData(SvStream& rStream)
 {
-  rStream.Read(Name, sizeof(Name));
-  //rStream.Read(&ValueFormat, sizeof(ValueFormat));
-  //rStream.Read(&LogFont, sizeof(LogFont));
+  lcl_ReadFixedString( rStream, Name, sizeof(Name));
   lcl_ReadValueFormat(rStream, ValueFormat);
   lcl_ReadLogFont(rStream, LogFont);
 
@@ -524,8 +535,7 @@ Sc10PatternCollection::Sc10PatternCollec
 	rStream >> nAnz;
 	for (sal_uInt16 i=0; (i < nAnz) && (nError == 0); i++)
 	{
-	  Insert(new Sc10PatternData(rStream));
-	  nError = rStream.GetError();
+        nError = insert_new<Sc10PatternData>( this, rStream);
 	}
   }
   else
@@ -543,8 +553,7 @@ Sc10PatternCollection::Sc10PatternCollec
 
 Sc10DataBaseData::Sc10DataBaseData(SvStream& rStream)
 {
-	//rStream.Read(&DataBaseRec, sizeof(DataBaseRec));
-	rStream.Read(&DataBaseRec.Name, sizeof(DataBaseRec.Name));
+	lcl_ReadFixedString( rStream, &DataBaseRec.Name, sizeof(DataBaseRec.Name));
 	rStream >> DataBaseRec.Tab;
 	lcl_ReadBlockRect(rStream, DataBaseRec.Block);
 	rStream >> DataBaseRec.RowHeader;
@@ -559,21 +568,21 @@ Sc10DataBaseData::Sc10DataBaseData(SvStr
 	rStream >> DataBaseRec.QueryField0;
 	rStream >> DataBaseRec.QueryOp0;
 	rStream >> DataBaseRec.QueryByString0;
-	rStream.Read(&DataBaseRec.QueryString0, sizeof(DataBaseRec.QueryString0));
+	lcl_ReadFixedString( rStream, &DataBaseRec.QueryString0, sizeof(DataBaseRec.QueryString0));
     DataBaseRec.QueryValue0 = ScfTools::ReadLongDouble(rStream);
 
 	rStream >> DataBaseRec.QueryConnect1;
 	rStream >> DataBaseRec.QueryField1;
 	rStream >> DataBaseRec.QueryOp1;
 	rStream >> DataBaseRec.QueryByString1;
-	rStream.Read(&DataBaseRec.QueryString1, sizeof(DataBaseRec.QueryString1));
+	lcl_ReadFixedString( rStream, &DataBaseRec.QueryString1, sizeof(DataBaseRec.QueryString1));
     DataBaseRec.QueryValue1 = ScfTools::ReadLongDouble(rStream);
 
 	rStream >> DataBaseRec.QueryConnect2;
 	rStream >> DataBaseRec.QueryField2;
 	rStream >> DataBaseRec.QueryOp2;
 	rStream >> DataBaseRec.QueryByString2;
-	rStream.Read(&DataBaseRec.QueryString2, sizeof(DataBaseRec.QueryString2));
+	lcl_ReadFixedString( rStream, &DataBaseRec.QueryString2, sizeof(DataBaseRec.QueryString2));
     DataBaseRec.QueryValue2 = ScfTools::ReadLongDouble(rStream);
 }
 
@@ -586,13 +595,12 @@ Sc10DataBaseCollection::Sc10DataBaseColl
   rStream >> ID;
   if (ID == DataBaseID)
   {
-	rStream.Read(ActName, sizeof(ActName));
+	lcl_ReadFixedString( rStream, ActName, sizeof(ActName));
 	sal_uInt16 nAnz;
 	rStream >> nAnz;
 	for (sal_uInt16 i=0; (i < nAnz) && (nError == 0); i++)
 	{
-	  Insert(new Sc10DataBaseData(rStream));
-	  nError = rStream.GetError();
+        nError = insert_new<Sc10DataBaseData>( this, rStream);
 	}
   }
   else
@@ -1042,7 +1050,6 @@ sal_uLong Sc10Import::Import()
 void Sc10Import::LoadFileHeader()
 {
 	Sc10FileHeader FileHeader;
-	//rStream.Read(&FileHeader, sizeof(FileHeader));
 	lcl_ReadFileHeader(rStream, FileHeader);
 
 	nError = rStream.GetError();
@@ -1085,7 +1092,6 @@ void Sc10Import::LoadEditStateInfo()
 
 void Sc10Import::LoadProtect()
 {
-	//rStream.Read(&SheetProtect, sizeof(SheetProtect));
 	lcl_ReadSheetProtect(rStream, SheetProtect);
 	nError = rStream.GetError();
 
@@ -1116,10 +1122,6 @@ void Sc10Import::LoadScrZoom()
 
 void Sc10Import::LoadPalette()
 {
-	//rStream.Read(TextPalette, sizeof(TextPalette));
-	//rStream.Read(BackPalette, sizeof(BackPalette));
-	//rStream.Read(RasterPalette, sizeof(RasterPalette));
-	//rStream.Read(FramePalette, sizeof(FramePalette));
 	lcl_ReadPalette(rStream, TextPalette);
 	lcl_ReadPalette(rStream, BackPalette);
 	lcl_ReadPalette(rStream, RasterPalette);
@@ -1132,12 +1134,16 @@ void Sc10Import::LoadPalette()
 void Sc10Import::LoadFontCollection()
 {
 	pFontCollection = new Sc10FontCollection(rStream);
+    if (!nError)
+        nError = pFontCollection->GetError();
 }
 
 
 void Sc10Import::LoadNameCollection()
 {
 	pNameCollection = new Sc10NameCollection(rStream);
+    if (!nError)
+        nError = pNameCollection->GetError();
 }
 
 
@@ -1158,6 +1164,10 @@ void Sc10Import::ImportNameCollection()
 void Sc10Import::LoadPatternCollection()
 {
 	pPatternCollection = new Sc10PatternCollection( rStream );
+    if (!nError)
+        nError = pPatternCollection->GetError();
+    if (nError == errOutOfMemory)
+        return;     // hopeless
 	ScStyleSheetPool* pStylePool = pDoc->GetStyleSheetPool();
 	for( sal_uInt16 i = 0 ; i < pPatternCollection->GetCount() ; i++ )
 	{
@@ -1249,9 +1259,6 @@ void Sc10Import::LoadPatternCollection()
                     rItemSet.Put( SfxInt32Item( ATTR_ROTATE_VALUE, 27000 ) );
 
 				sal_Int16 Margin = Max( ( sal_uInt16 ) 20, ( sal_uInt16 ) ( EJustify * 20 ) );
-//				if( ( ( OJustify & ojBottomTop ) == ojBottomTop ) ||
-//					( ( OJustify & ojBottomTop ) == ojBottomTop ) )
-// vielleicht so?
 				if( ( ( OJustify & ojBottomTop ) == ojBottomTop ) )
                     rItemSet.Put( SvxMarginItem( 20, Margin, 20, Margin, ATTR_MARGIN ) );
 				else
@@ -1391,6 +1398,10 @@ void Sc10Import::LoadPatternCollection()
 void Sc10Import::LoadDataBaseCollection()
 {
 	pDataBaseCollection = new Sc10DataBaseCollection(rStream);
+    if (!nError)
+        nError = pDataBaseCollection->GetError();
+    if (nError == errOutOfMemory)
+        return;     // hopeless
 	for( sal_uInt16 i = 0 ; i < pDataBaseCollection->GetCount() ; i++ )
 	{
 		Sc10DataBaseData* pOldData = pDataBaseCollection->At(i);
@@ -1432,7 +1443,6 @@ void Sc10Import::LoadTables()
 		String           aStr;	// Universal-Konvertierungs-String
 
 
-		//rStream.Read(&PageFormat, sizeof(PageFormat));
 		lcl_ReadPageFormat(rStream, PageFormat);
 
         sal_uInt16 nAt = aPageCollection.InsertFormat(PageFormat);
@@ -1442,7 +1452,6 @@ void Sc10Import::LoadTables()
 
 		rStream >> DataBaseIndex;
 
-		//rStream.Read(&TabProtect, sizeof(TabProtect));
 		lcl_ReadTabProtect(rStream, TabProtect);
 
         ScTableProtection aProtection;
@@ -1663,7 +1672,6 @@ void Sc10Import::LoadCol(SCCOL Col, SCTA
 					const SfxPoolItem* pValueFormat = pDoc->GetAttr(Col, static_cast<SCROW> (Row), Tab, ATTR_VALUE_FORMAT);
 					sal_uLong nFormat = ((SfxUInt32Item*)pValueFormat)->GetValue();
                     double Value = ScfTools::ReadLongDouble(rStream);
-					//rStream.Read(&Value, sizeof(Value));
 
 					// Achtung hier ist eine Anpassung Notwendig wenn Ihr das Basisdatum aendert
 					// In StarCalc 1.0 entspricht 0 dem 01.01.1900
@@ -1690,7 +1698,6 @@ void Sc10Import::LoadCol(SCCOL Col, SCTA
                     /*double Value =*/ ScfTools::ReadLongDouble(rStream);
 					sal_uInt8 Len;
 					sal_Char s[256+1];
-					//rStream.Read(&Value, sizeof(Value));
 					rStream >> Len;
 					rStream.Read(&s[1], Len);
 					s[0] = '=';
@@ -1764,29 +1771,29 @@ void Sc10Import::LoadColAttr(SCCOL Col, 
 		pColData = aFont.pData;
 		for( i = 0 ; i < nLimit ; i++, pColData++ )
 		{
-			//nEnd = aFont.pData[i].Row;
 			nEnd = static_cast<SCROW>(pColData->Row);
-			//if ((nStart <= nEnd) && (aFont.pData[i].Value != 0))
 			if ((nStart <= nEnd) && (pColData->Value))
 			{
                 FontFamily eFam = FAMILY_DONTKNOW;
-				//Sc10FontData* pFont = pFontCollection->At(aFont.pData[i].Value);
 				Sc10FontData* pFont = pFontCollection->At(pColData->Value);
-				switch (pFont->PitchAndFamily & 0xF0)
-				{
-					case ffDontCare   : eFam = FAMILY_DONTKNOW;		break;
-					case ffRoman      : eFam = FAMILY_ROMAN;		break;
-					case ffSwiss      : eFam = FAMILY_SWISS;		break;
-					case ffModern     : eFam = FAMILY_MODERN;		break;
-					case ffScript     : eFam = FAMILY_SCRIPT;		break;
-					case ffDecorative : eFam = FAMILY_DECORATIVE;	break;
-					default: eFam = FAMILY_DONTKNOW;		break;
-				}
-				ScPatternAttr aScPattern(pDoc->GetPool());
-                aScPattern.GetItemSet().Put(SvxFontItem(eFam, SC10TOSTRING( pFont->FaceName ), EMPTY_STRING,
-                    PITCH_DONTKNOW, RTL_TEXTENCODING_DONTKNOW, ATTR_FONT ));
-                aScPattern.GetItemSet().Put(SvxFontHeightItem(Abs(pFont->Height), 100, ATTR_FONT_HEIGHT ));
-				pDoc->ApplyPatternAreaTab(Col, nStart, Col, nEnd, Tab, aScPattern);
+                if (pFont)
+                {
+                    switch (pFont->PitchAndFamily & 0xF0)
+                    {
+                        case ffDontCare   : eFam = FAMILY_DONTKNOW;		break;
+                        case ffRoman      : eFam = FAMILY_ROMAN;		break;
+                        case ffSwiss      : eFam = FAMILY_SWISS;		break;
+                        case ffModern     : eFam = FAMILY_MODERN;		break;
+                        case ffScript     : eFam = FAMILY_SCRIPT;		break;
+                        case ffDecorative : eFam = FAMILY_DECORATIVE;	break;
+                        default: eFam = FAMILY_DONTKNOW;		break;
+                    }
+                    ScPatternAttr aScPattern(pDoc->GetPool());
+                    aScPattern.GetItemSet().Put(SvxFontItem(eFam, SC10TOSTRING( pFont->FaceName ), EMPTY_STRING,
+                        PITCH_DONTKNOW, RTL_TEXTENCODING_DONTKNOW, ATTR_FONT ));
+                    aScPattern.GetItemSet().Put(SvxFontHeightItem(Abs(pFont->Height), 100, ATTR_FONT_HEIGHT ));
+                    pDoc->ApplyPatternAreaTab(Col, nStart, Col, nEnd, Tab, aScPattern);
+                }
 			}
 			nStart = nEnd + 1;
 		}
@@ -1798,9 +1805,7 @@ void Sc10Import::LoadColAttr(SCCOL Col, 
 	pColData = aColor.pData;
 	for( i = 0 ; i < nLimit ; i++, pColData++ )
 	{
-		//nEnd = aColor.pData[i].Row;
 		nEnd = static_cast<SCROW>(pColData->Row);
-		//if ((nStart <= nEnd) && (aColor.pData[i].Value != 0))
 		if ((nStart <= nEnd) && (pColData->Value))
 		{
 			Color TextColor(COL_BLACK);
@@ -2174,36 +2179,31 @@ void Sc10Import::LoadColAttr(SCCOL Col, 
 		nStart = nEnd + 1;
 	}
   }
-
-  delete[] aFont.pData;
-  delete[] aAttr.pData;
-  delete[] aJustify.pData;
-  delete[] aFrame.pData;
-  delete[] aRaster.pData;
-  delete[] aValue.pData;
-  delete[] aColor.pData;
-  delete[] aFrameColor.pData;
-  delete[] aFlag.pData;
-  delete[] aPattern.pData;
 }
 
 
 void Sc10Import::LoadAttr(Sc10ColAttr& rAttr)
 {
-  rStream >> rAttr.Count;
-  rAttr.pData = new Sc10ColData[rAttr.Count];
-  if (rAttr.pData != NULL)
-  {
-	for (sal_uInt16 i = 0; i < rAttr.Count; i++)
-	{
-	  rStream >> rAttr.pData[i].Row;
-	  rStream >> rAttr.pData[i].Value;
-	}
-	//rStream.Read(rAttr.pData, rAttr.Count * sizeof(Sc10ColData));
-	nError = rStream.GetError();
-  }
-  else
-	nError = errOutOfMemory;
+    // rAttr is not reused, otherwise we'd have to delete [] rAttr.pData;
+    rStream >> rAttr.Count;
+    if (rAttr.Count)
+    {
+        rAttr.pData = new (::std::nothrow) Sc10ColData[rAttr.Count];
+        if (rAttr.pData != NULL)
+        {
+            for (sal_uInt16 i = 0; i < rAttr.Count; i++)
+            {
+                rStream >> rAttr.pData[i].Row;
+                rStream >> rAttr.pData[i].Value;
+            }
+            nError = rStream.GetError();
+        }
+        else
+        {
+            nError = errOutOfMemory;
+            rAttr.Count = 0;
+        }
+    }
 }
 
 
@@ -2389,7 +2389,6 @@ void Sc10Import::LoadObjects()
 	  for (sal_uInt16 i = 0; (i < nAnz) && (nError == 0) && !rStream.IsEof() && !IsOleObject; i++)
 	  {
 		rStream >> ObjectType;
-		//rStream.Read(&GraphHeader, sizeof(GraphHeader));
 		lcl_ReadGraphHeader(rStream, GraphHeader);
 
 		double nPPTX = ScGlobal::nScreenPPTX;
@@ -2447,7 +2446,6 @@ void Sc10Import::LoadObjects()
 		  case otImage :
 		  {
 		   Sc10ImageHeader ImageHeader;
-		   //rStream.Read(&ImageHeader, sizeof(ImageHeader));
 		   lcl_ReadImageHeaer(rStream, ImageHeader);
 
 		   // Achtung nun kommen die Daten (Bitmap oder Metafile)
@@ -2463,26 +2461,28 @@ void Sc10Import::LoadObjects()
 		  {
 			Sc10ChartHeader ChartHeader;
 			Sc10ChartSheetData ChartSheetData;
-			Sc10ChartTypeData* pTypeData = new Sc10ChartTypeData;
-			//rStream.Read(&ChartHeader, sizeof(ChartHeader));
-			lcl_ReadChartHeader(rStream, ChartHeader);
-
-			//!	altes Metafile verwenden ??
-			rStream.SeekRel(ChartHeader.Size);
-
-			//rStream.Read(&ChartSheetData, sizeof(ChartSheetData));
-			lcl_ReadChartSheetData(rStream, ChartSheetData);
-
-			//rStream.Read(pTypeData, sizeof(Sc10ChartTypeData));
-			lcl_ReadChartTypeData(rStream, *pTypeData);
-
-			Rectangle aRect( Point(nStartX,nStartY), Size(nSizeX,nSizeY) );
-			Sc10InsertObject::InsertChart( pDoc, static_cast<SCTAB>(GraphHeader.CarretZ), aRect,
-								static_cast<SCTAB>(GraphHeader.CarretZ),
-								ChartSheetData.DataX1, ChartSheetData.DataY1,
-								ChartSheetData.DataX2, ChartSheetData.DataY2 );
+			Sc10ChartTypeData* pTypeData = new (::std::nothrow) Sc10ChartTypeData;
+            if (!pTypeData)
+                nError = errOutOfMemory;
+            else
+            {
+                lcl_ReadChartHeader(rStream, ChartHeader);
+
+                //!	altes Metafile verwenden ??
+                rStream.SeekRel(ChartHeader.Size);
+
+                lcl_ReadChartSheetData(rStream, ChartSheetData);
+
+                lcl_ReadChartTypeData(rStream, *pTypeData);
+
+                Rectangle aRect( Point(nStartX,nStartY), Size(nSizeX,nSizeY) );
+                Sc10InsertObject::InsertChart( pDoc, static_cast<SCTAB>(GraphHeader.CarretZ), aRect,
+                        static_cast<SCTAB>(GraphHeader.CarretZ),
+                        ChartSheetData.DataX1, ChartSheetData.DataY1,
+                        ChartSheetData.DataX2, ChartSheetData.DataY2 );
 
-			delete pTypeData;
+                delete pTypeData;
+            }
 		  }
 		  break;
 		  default :

Modified: incubator/ooo/branches/writer001/main/sc/source/filter/xml/xmlfonte.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/branches/writer001/main/sc/source/filter/xml/xmlfonte.cxx?rev=1374979&r1=1374978&r2=1374979&view=diff
==============================================================================
--- incubator/ooo/branches/writer001/main/sc/source/filter/xml/xmlfonte.cxx (original)
+++ incubator/ooo/branches/writer001/main/sc/source/filter/xml/xmlfonte.cxx Mon Aug 20 11:46:19 2012
@@ -45,11 +45,15 @@
 
 class ScXMLFontAutoStylePool_Impl: public XMLFontAutoStylePool
 {
+private:
+    // #i120077# remember owned pool
+    SfxItemPool*    mpEditEnginePool;
+
 	void AddFontItems(sal_uInt16* pWhichIds, sal_uInt8 nIdCount, const SfxItemPool* pItemPool, const sal_Bool bExportDefaults);
-	public:
 
+public:
 	ScXMLFontAutoStylePool_Impl( ScXMLExport& rExport );
-
+    virtual ~ScXMLFontAutoStylePool_Impl();
 };
 
 void ScXMLFontAutoStylePool_Impl::AddFontItems(sal_uInt16* pWhichIds, sal_uInt8 nIdCount, const SfxItemPool* pItemPool, const sal_Bool bExportDefaults)
@@ -81,9 +85,9 @@ void ScXMLFontAutoStylePool_Impl::AddFon
 	}
 }
 
-ScXMLFontAutoStylePool_Impl::ScXMLFontAutoStylePool_Impl(
-	ScXMLExport& rExportP ) :
-	XMLFontAutoStylePool( rExportP )
+ScXMLFontAutoStylePool_Impl::ScXMLFontAutoStylePool_Impl(ScXMLExport& rExportP ) 
+:   XMLFontAutoStylePool(rExportP),
+    mpEditEnginePool(NULL)
 {
 	sal_uInt16 aWhichIds[3] = { ATTR_FONT, ATTR_CJK_FONT,
 								ATTR_CTL_FONT };
@@ -97,52 +101,77 @@ ScXMLFontAutoStylePool_Impl::ScXMLFontAu
 	const SfxItemPool* pEditPool(rExportP.GetDocument()->GetEditPool());
 	AddFontItems(aEditWhichIds, 3, pEditPool, sal_False);
 
-	SfxStyleSheetIterator* pItr(rExportP.GetDocument() ? rExportP.GetDocument()->GetStyleSheetPool()->CreateIterator(SFX_STYLE_FAMILY_PAGE, 0xFFFF) : NULL);
+	SfxStyleSheetIteratorPtr pItr;
+
+    if(rExportP.GetDocument())
+    {
+    	pItr = rExportP.GetDocument()->GetStyleSheetPool()->CreateIterator(SFX_STYLE_FAMILY_PAGE, 0xFFFF);
+    }
+
 	if(pItr)
 	{
 		SfxStyleSheetBase* pStyle(pItr->First());
-		SfxItemPool* pPageEditPool(EditEngine::CreatePool());
-		EditEngine aEditEngine(pPageEditPool);
-		while (pStyle)
-		{
-			const SfxItemPool& rPagePool(pStyle->GetPool().GetPool());
-			for (sal_uInt8 j = 0; j < 4; ++j)
-			{
-				sal_uInt16 nPageWhichId(aPageWhichIds[j]);
-				sal_uInt32 nPageHFItems(rPagePool.GetItemCount2(nPageWhichId));
-				const ScPageHFItem* pPageItem;
-				for (sal_uInt32 k = 0; k < nPageHFItems; ++k)
-				{
-					if (0 != (pPageItem = static_cast<const ScPageHFItem*>(rPagePool.GetItem2(nPageWhichId, k))))
-					{
-						const EditTextObject* pLeftArea(pPageItem->GetLeftArea());
-						if (pLeftArea)
-						{
-							aEditEngine.SetText(*pLeftArea);
-							AddFontItems(aEditWhichIds, 3, pPageEditPool, sal_False);
-						}
-						const EditTextObject* pCenterArea(pPageItem->GetCenterArea());
-						if (pCenterArea)
-						{
-							aEditEngine.SetText(*pCenterArea);
-							AddFontItems(aEditWhichIds, 3, pPageEditPool, sal_False);
-						}
-						const EditTextObject* pRightArea(pPageItem->GetRightArea());
-						if (pRightArea)
-						{
-							aEditEngine.SetText(*pRightArea);
-							AddFontItems(aEditWhichIds, 3, pPageEditPool, sal_False);
-						}
+        
+        if(pStyle)
+        {
+            // #i120077# remember the SfxItemPool in member variable before usage. The
+            // local EditEngine will not take over ownership of the pool.
+            mpEditEnginePool = EditEngine::CreatePool();
+		    EditEngine aEditEngine(mpEditEnginePool);
+
+		    while (pStyle)
+		    {
+			    const SfxItemPool& rPagePool(pStyle->GetPool().GetPool());
+			    
+                for (sal_uInt8 j = 0; j < 4; ++j)
+			    {
+				    sal_uInt16 nPageWhichId(aPageWhichIds[j]);
+				    sal_uInt32 nPageHFItems(rPagePool.GetItemCount2(nPageWhichId));
+				    const ScPageHFItem* pPageItem;
+				    for (sal_uInt32 k = 0; k < nPageHFItems; ++k)
+				    {
+					    if (0 != (pPageItem = static_cast<const ScPageHFItem*>(rPagePool.GetItem2(nPageWhichId, k))))
+					    {
+						    const EditTextObject* pLeftArea(pPageItem->GetLeftArea());
+						    if (pLeftArea)
+						    {
+							    aEditEngine.SetText(*pLeftArea);
+							    AddFontItems(aEditWhichIds, 3, mpEditEnginePool, sal_False);
+						    }
+						    const EditTextObject* pCenterArea(pPageItem->GetCenterArea());
+						    if (pCenterArea)
+						    {
+							    aEditEngine.SetText(*pCenterArea);
+							    AddFontItems(aEditWhichIds, 3, mpEditEnginePool, sal_False);
+						    }
+						    const EditTextObject* pRightArea(pPageItem->GetRightArea());
+						    if (pRightArea)
+						    {
+							    aEditEngine.SetText(*pRightArea);
+							    AddFontItems(aEditWhichIds, 3, mpEditEnginePool, sal_False);
+						    }
+                        }
 					}
 				}
+    
+                pStyle = pItr->Next();
 			}
-			pStyle = pItr->Next();
 		}
 	}
 }
 
+ScXMLFontAutoStylePool_Impl::~ScXMLFontAutoStylePool_Impl()
+{
+    if(mpEditEnginePool)
+    {
+        // memory leak #i120077#
+        SfxItemPool::Free(mpEditEnginePool);
+    }
+}
 
 XMLFontAutoStylePool* ScXMLExport::CreateFontAutoStylePool()
 {
 	return new ScXMLFontAutoStylePool_Impl( *this );
 }
+
+// eof

Modified: incubator/ooo/branches/writer001/main/sc/source/ui/dbgui/dbnamdlg.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/branches/writer001/main/sc/source/ui/dbgui/dbnamdlg.cxx?rev=1374979&r1=1374978&r2=1374979&view=diff
==============================================================================
--- incubator/ooo/branches/writer001/main/sc/source/ui/dbgui/dbnamdlg.cxx (original)
+++ incubator/ooo/branches/writer001/main/sc/source/ui/dbgui/dbnamdlg.cxx Mon Aug 20 11:46:19 2012
@@ -266,7 +266,8 @@ void ScDbNameDlg::Init()
 					&& (rEnd.Col()   == nCol2) && (rEnd.Row()   == nRow2 ) )
 				{
 					pDBData->GetName( theDbName );
-					if ( theDbName != aStrNoName )
+					//if ( theDbName != aStrNoName )
+					if ( !pDBData->IsBuildin() )
 						aEdName.SetText( theDbName );
 					else
 						aEdName.SetText( EMPTY_STRING );
@@ -378,7 +379,8 @@ void ScDbNameDlg::UpdateNames()
 			if ( pDbData )
 			{
 				pDbData->GetName( aString );
-				if ( aString != aStrNoName )
+				//if ( aString != aStrNoName )
+				if ( !pDbData->IsBuildin() )
 					aEdName.InsertEntry( aString );
 			}
 		}

Modified: incubator/ooo/branches/writer001/main/sc/source/ui/dbgui/foptmgr.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/branches/writer001/main/sc/source/ui/dbgui/foptmgr.cxx?rev=1374979&r1=1374978&r2=1374979&view=diff
==============================================================================
--- incubator/ooo/branches/writer001/main/sc/source/ui/dbgui/foptmgr.cxx (original)
+++ incubator/ooo/branches/writer001/main/sc/source/ui/dbgui/foptmgr.cxx Mon Aug 20 11:46:19 2012
@@ -186,7 +186,7 @@ void ScFilterOptionsMgr::Init()
 				rBtnHeader.Check( pDBData->HasHeader() );
 				pDBData->GetName( theDbName );
 
-				if ( theDbName != rStrNoName )
+                if ( !pDBData->IsBuildin() )
 				{
 					rBtnHeader.Disable();
 				}

Modified: incubator/ooo/branches/writer001/main/sc/source/ui/dbgui/scuiasciiopt.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/branches/writer001/main/sc/source/ui/dbgui/scuiasciiopt.cxx?rev=1374979&r1=1374978&r2=1374979&view=diff
==============================================================================
--- incubator/ooo/branches/writer001/main/sc/source/ui/dbgui/scuiasciiopt.cxx (original)
+++ incubator/ooo/branches/writer001/main/sc/source/ui/dbgui/scuiasciiopt.cxx Mon Aug 20 11:46:19 2012
@@ -245,7 +245,6 @@ ScImportAsciiDlg::ScImportAsciiDlg( Wind
 
 		aCharSetUser( ScResId( SCSTR_CHARSET_USER ) ),
 		aColumnUser	( ScResId( SCSTR_COLUMN_USER ) ),
-		aFldSepList	( ScResId( SCSTR_FIELDSEP ) ),
 		aTextSepList( ScResId( SCSTR_TEXTSEP ) ),
         mcTextSep   ( ScAsciiOptions::cDefaultTextSep ),
         maStrTextToColumns( ScResId( STR_TEXTTOCOLUMNS ) ),

Modified: incubator/ooo/branches/writer001/main/sc/source/ui/dbgui/scuiimoptdlg.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/branches/writer001/main/sc/source/ui/dbgui/scuiimoptdlg.cxx?rev=1374979&r1=1374978&r2=1374979&view=diff
==============================================================================
--- incubator/ooo/branches/writer001/main/sc/source/ui/dbgui/scuiimoptdlg.cxx (original)
+++ incubator/ooo/branches/writer001/main/sc/source/ui/dbgui/scuiimoptdlg.cxx Mon Aug 20 11:46:19 2012
@@ -135,8 +135,12 @@ ScImportOptionsDlg::ScImportOptionsDlg(
 		aBtnCancel	( this, ScResId( BTN_CANCEL ) ),
         aBtnHelp	( this, ScResId( BTN_HELP ) )
 {
+    String sFieldSep( ScResId( SCSTR_FIELDSEP ) );
+    sFieldSep.SearchAndReplaceAscii( "%TAB",   String(ScResId(SCSTR_FIELDSEP_TAB)) );
+    sFieldSep.SearchAndReplaceAscii( "%SPACE", String(ScResId(SCSTR_FIELDSEP_SPACE)) );
+
 	// im Ctor-Initializer nicht moeglich (MSC kann das nicht):
-	pFieldSepTab = new ScDelimiterTable( String(ScResId(SCSTR_FIELDSEP)) );
+	pFieldSepTab = new ScDelimiterTable( sFieldSep );
 	pTextSepTab  = new ScDelimiterTable( String(ScResId(SCSTR_TEXTSEP)) );
 
 	String aStr = pFieldSepTab->FirstDel();

Modified: incubator/ooo/branches/writer001/main/sc/source/ui/docshell/dbdocfun.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/branches/writer001/main/sc/source/ui/docshell/dbdocfun.cxx?rev=1374979&r1=1374978&r2=1374979&view=diff
==============================================================================
--- incubator/ooo/branches/writer001/main/sc/source/ui/docshell/dbdocfun.cxx (original)
+++ incubator/ooo/branches/writer001/main/sc/source/ui/docshell/dbdocfun.cxx Mon Aug 20 11:46:19 2012
@@ -592,7 +592,7 @@ sal_Bool ScDBDocFunc::Sort( SCTAB nTab, 
 		if (pDestData)
 			pNewData = pDestData;				// Bereich vorhanden -> anpassen
 		else									// Bereich ab Cursor/Markierung wird angelegt
-			pNewData = rDocShell.GetDBData(aDestPos, SC_DB_MAKE, SC_DBSEL_FORCE_MARK );
+			pNewData = rDocShell.GetDBData(aDestPos, SC_DB_MAKE_SORT, SC_DBSEL_FORCE_MARK );
 		if (pNewData)
 		{
 			pNewData->SetArea( nTab,
@@ -919,7 +919,7 @@ sal_Bool ScDBDocFunc::Query( SCTAB nTab,
 			pNewData = rDocShell.GetDBData(
 							ScRange( aLocalParam.nCol1, aLocalParam.nRow1, nDestTab,
 									 aLocalParam.nCol2, aLocalParam.nRow2, nDestTab ),
-							SC_DB_MAKE, SC_DBSEL_FORCE_MARK );
+							SC_DB_MAKE_FILTER, SC_DBSEL_FORCE_MARK );
 
 		if (pNewData)
 		{

Modified: incubator/ooo/branches/writer001/main/sc/source/ui/docshell/docsh5.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/branches/writer001/main/sc/source/ui/docshell/docsh5.cxx?rev=1374979&r1=1374978&r2=1374979&view=diff
==============================================================================
--- incubator/ooo/branches/writer001/main/sc/source/ui/docshell/docsh5.cxx (original)
+++ incubator/ooo/branches/writer001/main/sc/source/ui/docshell/docsh5.cxx Mon Aug 20 11:46:19 2012
@@ -150,6 +150,8 @@ ScDBData* lcl_GetDBNearCursor( ScDBColle
 
 ScDBData* ScDocShell::GetDBData( const ScRange& rMarked, ScGetDBMode eMode, ScGetDBSelection eSel )
 {
+    if ( eMode == SC_DB_MAKE_FILTER || eMode == SC_DB_MAKE_SORT || eMode == SC_DB_MAKE_SUBTOTAL || eMode == SC_DB_OLD_FILTER )
+        return GetDBDataAdd(rMarked, eMode, eSel);
 	SCCOL nCol = rMarked.aStart.Col();
 	SCROW nRow = rMarked.aStart.Row();
 	SCTAB nTab = rMarked.aStart.Tab();
@@ -184,7 +186,8 @@ ScDBData* ScDocShell::GetDBData( const S
 		SCCOL nOldCol2;
 		SCROW nOldRow2;
 		pData->GetArea( nDummy, nOldCol1,nOldRow1, nOldCol2,nOldRow2 );
-		sal_Bool bIsNoName = ( pData->GetName() == ScGlobal::GetRscString( STR_DB_NONAME ) );
+//		sal_Bool bIsNoName = ( pData->GetName() == ScGlobal::GetRscString( STR_DB_NONAME ) );
+		sal_Bool bIsNoName = pData->IsBuildin();
 
 		if (!bSelected)
 		{
@@ -322,7 +325,9 @@ ScDBData* ScDocShell::GetDBData( const S
 				while (pColl->SearchName( aNewName, nDummy ));
 			}
 			else
-				aNewName = ScGlobal::GetRscString( STR_DB_NONAME );
+				//aNewName = ScGlobal::GetRscString( STR_DB_NONAME );
+				aNewName = pColl->GetNewDefaultDBName();
+
 			pNoNameData = new ScDBData( aNewName, nTab,
 								nStartCol,nStartRow, nEndCol,nEndRow,
 								sal_True, bHasHeader );
@@ -351,6 +356,168 @@ ScDBData* ScDocShell::GetDBData( const S
 	return pData;
 }
 
+ScDBData* ScDocShell::GetDBDataAdd( const ScRange& rMarked, ScGetDBMode eMode, ScGetDBSelection eSel )
+{
+    SCCOL nCol = rMarked.aStart.Col();
+    SCROW nRow = rMarked.aStart.Row();
+    SCTAB nTab = rMarked.aStart.Tab();
+
+    SCCOL nStartCol = nCol;
+    SCROW nStartRow = nRow;
+    SCCOL nEndCol = rMarked.aEnd.Col();
+    SCROW nEndRow = rMarked.aEnd.Row();
+
+    ScDBData* pData = NULL;
+    ScDBData* pCursorData;
+    pCursorData = aDocument.GetDBAtArea( nTab, nStartCol, nStartRow, nEndCol, nEndRow );
+    if ( !pCursorData )
+        pCursorData = aDocument.GetDBAtCursor( nStartCol, nStartRow, nTab );
+
+    //Get DBData at current table
+    ScDBData* pTableData = aDocument.GetDBAtTable( nTab, eMode );
+
+    if ( eMode == SC_DB_OLD_FILTER )
+        return pTableData;
+
+    sal_Bool bSelected = ( eSel == SC_DBSEL_FORCE_MARK || rMarked.aStart != rMarked.aEnd ); 
+    bool bOnlyDown = (!bSelected && eSel == SC_DBSEL_ROW_DOWN && rMarked.aStart.Row() == rMarked.aEnd.Row());
+
+	sal_Bool bUseThis = sal_False;
+    if (pCursorData)
+    {
+        SCTAB nDummy;
+        SCCOL nOldCol1;
+        SCROW nOldRow1;
+        SCCOL nOldCol2;
+        SCROW nOldRow2;
+        pCursorData->GetArea( nDummy, nOldCol1,nOldRow1, nOldCol2,nOldRow2 );
+        if ( !bSelected )
+        {    
+              ScRange tmpRange;
+              if ( !pCursorData->IsBuildin() && pCursorData->GetAdvancedQuerySource(tmpRange))	 
+                   bUseThis = sal_True;			   
+              else
+             {  
+                 nStartCol = nCol;
+                 nStartRow = nRow;
+                 nEndCol = nStartCol;
+                 nEndRow = nStartRow;
+				aDocument.GetDataArea( nTab, nStartCol, nStartRow, nEndCol, nEndRow, sal_False, bOnlyDown );
+                 if ( nOldCol1 != nStartCol || nOldCol2 != nEndCol || nOldRow1 != nStartRow )
+                     bUseThis = sal_False;
+                 else
+                 {
+                     bUseThis = sal_True;
+                     if ( nOldRow2 != nEndRow )// Range of new end-line expand
+                     pCursorData->SetArea( nTab, nOldCol1,nOldRow1, nOldCol2,nEndRow );
+                 }
+            }
+
+        }
+        else
+        {
+            if ( nOldCol1 == nStartCol && nOldRow1 == nStartRow && nOldCol2 == nEndCol && nOldRow2 == nEndRow )
+				bUseThis = sal_True;
+            else
+				bUseThis = sal_False;			// Always take mark (Bug 11964)
+        }
+    }
+
+    if ( bUseThis )
+    {
+        pData = pCursorData;
+        if ( pTableData && eMode == SC_DB_MAKE_FILTER && !(*pTableData == *pCursorData ) )
+        {
+            if ( !pOldAutoDBRange )
+                pOldAutoDBRange = new ScDBData(*pTableData);
+            SCCOL nOldX1;
+            SCROW nOldY1;
+            SCCOL nOldX2;
+            SCROW nOldY2;
+            SCTAB nOldTab;
+            pTableData->GetArea( nOldTab, nOldX1, nOldY1, nOldX2, nOldY2 );
+
+            if (pTableData->HasQueryParam())
+            {
+                ScQueryParam    aParam;
+                pTableData->GetQueryParam(aParam);
+                SCSIZE nEC = aParam.GetEntryCount();
+                for (SCSIZE i=0; i<nEC; i++)
+                    aParam.GetEntry(i).bDoQuery = sal_False;
+                aParam.bDuplicate = sal_True;
+                ScDBDocFunc aDBDocFunc( *this );
+                aDBDocFunc.Query( nTab, aParam, NULL, sal_False, sal_False );
+            }
+
+            DBAreaDeleted( nOldTab, nOldX1, nOldY1, nOldX2, nOldY2 );
+            pTableData->SetQueryParam( ScQueryParam() );
+            pTableData->SetAutoFilter( sal_False );
+        }
+
+    }
+    else
+    {
+        if ( bSelected )
+        {
+//			bMark = sal_False;
+        }
+        else
+        {
+            nStartCol = nCol;
+            nStartRow = nRow;
+            nEndCol = nStartCol;
+            nEndRow = nStartRow;
+			aDocument.GetDataArea( nTab, nStartCol, nStartRow, nEndCol, nEndRow, sal_False, bOnlyDown );
+        }
+        sal_Bool bHasHeader = aDocument.HasColHeader( nStartCol,nStartRow, nEndCol,nEndRow, nTab );
+        ScDBCollection* pColl = aDocument.GetDBCollection();
+        if ( pTableData )
+        {
+            if ( !pOldAutoDBRange )
+                pOldAutoDBRange = new ScDBData(*pTableData);
+            SCCOL nOldX1;
+            SCROW nOldY1;
+            SCCOL nOldX2;
+            SCROW nOldY2;
+            SCTAB nOldTab;
+            pTableData->GetArea( nOldTab, nOldX1, nOldY1, nOldX2, nOldY2 );
+
+            if (pTableData->HasQueryParam())
+            {
+                ScQueryParam    aParam;
+                pTableData->GetQueryParam(aParam);
+                SCSIZE nEC = aParam.GetEntryCount();
+                for (SCSIZE i=0; i<nEC; i++)
+                    aParam.GetEntry(i).bDoQuery = sal_False;
+                aParam.bDuplicate = sal_True;
+                ScDBDocFunc aDBDocFunc( *this );
+                aDBDocFunc.Query( nTab, aParam, NULL, sal_False, sal_False );
+            }
+
+                DBAreaDeleted( nOldTab, nOldX1, nOldY1, nOldX2, nOldY2 );
+
+            pTableData->SetSortParam( ScSortParam() );
+            pTableData->SetQueryParam( ScQueryParam() );
+            pTableData->SetSubTotalParam( ScSubTotalParam() );
+
+            pTableData->SetArea( nTab, nStartCol, nStartRow, nEndCol, nEndRow );
+            pTableData->SetByRow( sal_True );
+            pTableData->SetHeader( bHasHeader );
+            pTableData->SetAutoFilter( sal_False );
+        }
+        else
+        {
+            String aNewName = pColl->GetNewDefaultDBName();
+            pTableData = new ScDBData( aNewName, nTab, nStartCol,nStartRow, nEndCol,nEndRow, sal_True, bHasHeader );
+            pColl->Insert( pTableData );
+        }
+        pData = pTableData;
+    }
+
+    return pData;
+}
+
+
 ScDBData* ScDocShell::GetOldAutoDBRange()
 {
     ScDBData* pRet = pOldAutoDBRange;

Modified: incubator/ooo/branches/writer001/main/sc/source/ui/inc/dbfunc.hxx
URL: http://svn.apache.org/viewvc/incubator/ooo/branches/writer001/main/sc/source/ui/inc/dbfunc.hxx?rev=1374979&r1=1374978&r2=1374979&view=diff
==============================================================================
--- incubator/ooo/branches/writer001/main/sc/source/ui/inc/dbfunc.hxx (original)
+++ incubator/ooo/branches/writer001/main/sc/source/ui/inc/dbfunc.hxx Mon Aug 20 11:46:19 2012
@@ -75,6 +75,7 @@ public:
 					// DB-Bereich vom Cursor
 	ScDBData* 		GetDBData( sal_Bool bMarkArea = sal_True, ScGetDBMode eMode = SC_DB_MAKE, ScGetDBSelection eSel = SC_DBSEL_KEEP );
 
+    //ScRange         GetDBRange( BOOL bMark, bool bIgnoreNotes );
 	void			NotifyCloseDbNameDlg( const ScDBCollection& rNewColl, const List& rDelAreaList );
 
 	void			Consolidate( const ScConsolidateParam& rParam, sal_Bool bRecord = sal_True );

Modified: incubator/ooo/branches/writer001/main/sc/source/ui/inc/docsh.hxx
URL: http://svn.apache.org/viewvc/incubator/ooo/branches/writer001/main/sc/source/ui/inc/docsh.hxx?rev=1374979&r1=1374978&r2=1374979&view=diff
==============================================================================
--- incubator/ooo/branches/writer001/main/sc/source/ui/inc/docsh.hxx (original)
+++ incubator/ooo/branches/writer001/main/sc/source/ui/inc/docsh.hxx Mon Aug 20 11:46:19 2012
@@ -158,6 +158,7 @@ class SC_DLLPUBLIC ScDocShell: public Sf
 
     SC_DLLPRIVATE void          EnableSharedSettings( bool bEnable );
     SC_DLLPRIVATE ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > LoadSharedDocument();
+	ScDBData*		GetDBDataAdd( const ScRange& rMarked, ScGetDBMode eMode, ScGetDBSelection eSel );
 
     SC_DLLPRIVATE void          UseSheetSaveEntries();
 
@@ -306,6 +307,7 @@ public:
 	ScDBData*		GetDBData( const ScRange& rMarked, ScGetDBMode eMode, ScGetDBSelection eSel );
     ScDBData*       GetOldAutoDBRange();    // has to be deleted by caller!
     void            CancelAutoDBRange();    // called when dialog is cancelled
+	ScDBCollection* GetDBCollection(){ return aDocument.GetDBCollection();}
 
 	void			UpdateLinks();			// Link-Eintraege aktuallisieren
 	sal_Bool			ReloadTabLinks();		// Links ausfuehren (Inhalt aktualisieren)

Modified: incubator/ooo/branches/writer001/main/sc/source/ui/inc/drawview.hxx
URL: http://svn.apache.org/viewvc/incubator/ooo/branches/writer001/main/sc/source/ui/inc/drawview.hxx?rev=1374979&r1=1374978&r2=1374979&view=diff
==============================================================================
--- incubator/ooo/branches/writer001/main/sc/source/ui/inc/drawview.hxx (original)
+++ incubator/ooo/branches/writer001/main/sc/source/ui/inc/drawview.hxx Mon Aug 20 11:46:19 2012
@@ -33,6 +33,7 @@ namespace com { namespace sun { namespac
 class ScDocument;
 class ScViewData;
 class ScDrawObjData;
+class SdrUndoManager;
 
 class ScDrawView: public FmFormView
 {
@@ -58,6 +59,9 @@ protected:
 
 	void ImplClearCalcDropMarker();
 
+    // support enhanced text edit for draw objects
+    virtual SdrUndoManager* getSdrUndoManagerForEnhancedTextEdit() const;
+
 public:
 					ScDrawView( OutputDevice* pOut, ScViewData* pData );
 	virtual			~ScDrawView();

Modified: incubator/ooo/branches/writer001/main/sc/source/ui/inc/scuiasciiopt.hxx
URL: http://svn.apache.org/viewvc/incubator/ooo/branches/writer001/main/sc/source/ui/inc/scuiasciiopt.hxx?rev=1374979&r1=1374978&r2=1374979&view=diff
==============================================================================
--- incubator/ooo/branches/writer001/main/sc/source/ui/inc/scuiasciiopt.hxx (original)
+++ incubator/ooo/branches/writer001/main/sc/source/ui/inc/scuiasciiopt.hxx Mon Aug 20 11:46:19 2012
@@ -82,7 +82,6 @@ class ScImportAsciiDlg : public ModalDia
 
     String                      aCharSetUser;
     String                      aColumnUser;
-    String                      aFldSepList;
     String                      aTextSepList;
     String                      maFieldSeparators;  // selected field separators
 	sal_Unicode                 mcTextSep;

Modified: incubator/ooo/branches/writer001/main/sc/source/ui/navipi/content.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/branches/writer001/main/sc/source/ui/navipi/content.cxx?rev=1374979&r1=1374978&r2=1374979&view=diff
==============================================================================
--- incubator/ooo/branches/writer001/main/sc/source/ui/navipi/content.cxx (original)
+++ incubator/ooo/branches/writer001/main/sc/source/ui/navipi/content.cxx Mon Aug 20 11:46:19 2012
@@ -734,7 +734,8 @@ void ScContentTree::GetDbNames()
 		{
 			ScDBData* pData = (*pDbNames)[i];
 			String aStrName = pData->GetName();
-			if ( aStrName != aStrNoName )
+			//if ( aStrName != aStrNoName )
+			if ( !pData->IsBuildin() )
 				InsertContent( SC_CONTENT_DBAREA, aStrName );
 		}
 	}

Modified: incubator/ooo/branches/writer001/main/sc/source/ui/src/optdlg.src
URL: http://svn.apache.org/viewvc/incubator/ooo/branches/writer001/main/sc/source/ui/src/optdlg.src?rev=1374979&r1=1374978&r2=1374979&view=diff
==============================================================================
--- incubator/ooo/branches/writer001/main/sc/source/ui/src/optdlg.src (original)
+++ incubator/ooo/branches/writer001/main/sc/source/ui/src/optdlg.src Mon Aug 20 11:46:19 2012
@@ -160,7 +160,7 @@ TabPage RID_SCPAGE_CALC
     {
         HelpID = "sc:CheckBox:RID_SCPAGE_CALC:BTN_GENERAL_PREC";
         Pos = MAP_APPFONT ( 12 , 147 ) ;
-        Size = MAP_APPFONT ( 148 , 10 ) ;
+        Size = MAP_APPFONT ( 200 , 10 ) ;
         Text [ en-US ] = "Limit decimals for general number format" ;
     };
     FixedText FT_PREC

Modified: incubator/ooo/branches/writer001/main/sc/source/ui/src/scstring.src
URL: http://svn.apache.org/viewvc/incubator/ooo/branches/writer001/main/sc/source/ui/src/scstring.src?rev=1374979&r1=1374978&r2=1374979&view=diff
==============================================================================
--- incubator/ooo/branches/writer001/main/sc/source/ui/src/scstring.src (original)
+++ incubator/ooo/branches/writer001/main/sc/source/ui/src/scstring.src Mon Aug 20 11:46:19 2012
@@ -482,7 +482,17 @@ String SCSTR_COLUMN_USER
 
 String SCSTR_FIELDSEP
 {
-	Text [ en-US ] = ",\t44\t;\t59\t:\t58\t{Tab}\t9\t{space}\t32 " ;
+	Text = ",\t44\t;\t59\t:\t58\t{%TAB}\t9\t{%SPACE}\t32 " ;
+};
+
+String SCSTR_FIELDSEP_TAB
+{
+    Text [ en-US ] = "Tab" ;
+};
+
+String SCSTR_FIELDSEP_SPACE
+{
+    Text [ en-US ] = "space" ;
 };
 
 String SCSTR_TEXTSEP

Modified: incubator/ooo/branches/writer001/main/sc/source/ui/undo/undobase.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/branches/writer001/main/sc/source/ui/undo/undobase.cxx?rev=1374979&r1=1374978&r2=1374979&view=diff
==============================================================================
--- incubator/ooo/branches/writer001/main/sc/source/ui/undo/undobase.cxx (original)
+++ incubator/ooo/branches/writer001/main/sc/source/ui/undo/undobase.cxx Mon Aug 20 11:46:19 2012
@@ -33,6 +33,7 @@
 #include "undobase.hxx"
 #include "refundo.hxx"
 #include "docsh.hxx"
+#include "dbdocfun.hxx"
 #include "tabvwsh.hxx"
 #include "undoolk.hxx"
 #include "undodraw.hxx"
@@ -390,7 +391,7 @@ void ScDBFuncUndo::EndUndo()
         sal_uInt16 nNoNameIndex;
         ScDocument* pDoc = pDocShell->GetDocument();
         ScDBCollection* pColl = pDoc->GetDBCollection();
-        if ( pColl->SearchName( ScGlobal::GetRscString( STR_DB_NONAME ), nNoNameIndex ) )
+        if ( pColl->SearchName( pAutoDBRange->GetName(), nNoNameIndex ) )
         {
             ScDBData* pNoNameData = (*pColl)[nNoNameIndex];
 
@@ -403,6 +404,13 @@ void ScDBFuncUndo::EndUndo()
             pDocShell->DBAreaDeleted( nRangeTab, nRangeX1, nRangeY1, nRangeX2, nRangeY2 );
 
             *pNoNameData = *pAutoDBRange;
+            /*if (pAutoDBRange->HasQueryParam())   //maybe conflict with AOO
+            {
+                ScQueryParam    aParam;
+                pAutoDBRange->GetQueryParam(aParam);
+                ScDBDocFunc aDBDocFunc( *pDocShell );
+                aDBDocFunc.Query( nRangeTab, aParam, NULL, sal_False, sal_False );
+            }*/
 
             if ( pAutoDBRange->HasAutoFilter() )
             {
@@ -425,7 +433,7 @@ void ScDBFuncUndo::BeginRedo()
         sal_uInt16 nNoNameIndex;
         ScDocument* pDoc = pDocShell->GetDocument();
         ScDBCollection* pColl = pDoc->GetDBCollection();
-        if ( pColl->SearchName( ScGlobal::GetRscString( STR_DB_NONAME ), nNoNameIndex ) )
+        if ( pColl->SearchName( pAutoDBRange->GetName(), nNoNameIndex ) )
         {
             ScDBData* pNoNameData = (*pColl)[nNoNameIndex];
 
@@ -435,6 +443,17 @@ void ScDBFuncUndo::BeginRedo()
             SCROW nRangeY2;
             SCTAB nRangeTab;
             pNoNameData->GetArea( nRangeTab, nRangeX1, nRangeY1, nRangeX2, nRangeY2 );
+            /*if (pAutoDBRange->HasQueryParam())
+            {
+                ScQueryParam    aParam;
+                pAutoDBRange->GetQueryParam(aParam);
+                SCSIZE nEC = aParam.GetEntryCount();
+                for (SCSIZE i=0; i<nEC; i++)
+                    aParam.GetEntry(i).bDoQuery = sal_False;
+                aParam.bDuplicate = sal_True;
+                ScDBDocFunc aDBDocFunc( *pDocShell );
+                aDBDocFunc.Query( nRangeTab, aParam, NULL, sal_False, sal_False );
+            }*/
             pDocShell->DBAreaDeleted( nRangeTab, nRangeX1, nRangeY1, nRangeX2, nRangeY2 );
 
             pNoNameData->SetSortParam( ScSortParam() );

Modified: incubator/ooo/branches/writer001/main/sc/source/ui/undo/undoutil.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/branches/writer001/main/sc/source/ui/undo/undoutil.cxx?rev=1374979&r1=1374978&r2=1374979&view=diff
==============================================================================
--- incubator/ooo/branches/writer001/main/sc/source/ui/undo/undoutil.cxx (original)
+++ incubator/ooo/branches/writer001/main/sc/source/ui/undo/undoutil.cxx Mon Aug 20 11:46:19 2012
@@ -93,7 +93,8 @@ ScDBData* ScUndoUtil::GetOldDBData( ScDB
 		{
 			String aName;
 			pUndoData->GetName( aName );
-			if ( aName == ScGlobal::GetRscString( STR_DB_NONAME ) )
+//			if ( aName == ScGlobal::GetRscString( STR_DB_NONAME ) )
+			if (pUndoData->IsBuildin())
 				bWasTemp = sal_True;
 		}
         DBG_ASSERT(bWasTemp, "Undo: didn't find database range");
@@ -104,7 +105,8 @@ ScDBData* ScUndoUtil::GetOldDBData( ScDB
 			pRet = (*pColl)[nIndex];
 		else
 		{
-			pRet = new ScDBData( ScGlobal::GetRscString( STR_DB_NONAME ), nTab,
+            String	aNoNamed = pColl->GetNewDefaultDBName();
+			pRet = new ScDBData( aNoNamed/*ScGlobal::GetRscString( STR_DB_NONAME )*/, nTab,
 								nCol1,nRow1, nCol2,nRow2, sal_True,
 								pDoc->HasColHeader( nCol1,nRow1,nCol2,nRow2,nTab ) );
 			pColl->Insert( pRet );

Modified: incubator/ooo/branches/writer001/main/sc/source/ui/unoobj/cellsuno.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/branches/writer001/main/sc/source/ui/unoobj/cellsuno.cxx?rev=1374979&r1=1374978&r2=1374979&view=diff
==============================================================================
--- incubator/ooo/branches/writer001/main/sc/source/ui/unoobj/cellsuno.cxx (original)
+++ incubator/ooo/branches/writer001/main/sc/source/ui/unoobj/cellsuno.cxx Mon Aug 20 11:46:19 2012
@@ -3464,8 +3464,8 @@ uno::Reference<sheet::XSheetCellRanges> 
 
 		ScRangeList aNewRanges;
 		//	IsMultiMarked reicht hier nicht (wird beim deselektieren nicht zurueckgesetzt)
-		if (aMarkData.HasAnyMultiMarks())
-			aMarkData.FillRangeListWithMarks( &aNewRanges, sal_False );
+		//if (aMarkData.HasAnyMultiMarks()) // #20044# should be set for all empty range
+		aMarkData.FillRangeListWithMarks( &aNewRanges, sal_False );
 
 		return new ScCellRangesObj( pDocShell, aNewRanges );	// aNewRanges kann leer sein
 	}
@@ -7365,31 +7365,43 @@ void SAL_CALL ScTableSheetObj::copyRange
 void ScTableSheetObj::PrintAreaUndo_Impl( ScPrintRangeSaver* pOldRanges )
 {
 	//	Umbrueche und Undo
-
 	ScDocShell* pDocSh = GetDocShell();
-	if ( pDocSh )
+	ScDocument* pDoc = pDocSh ? pDocSh->GetDocument() : 0;
+
+    if(pDocSh && pDoc)
 	{
-		ScDocument* pDoc = pDocSh->GetDocument();
-		sal_Bool bUndo(pDoc->IsUndoEnabled());
-		SCTAB nTab = GetTab_Impl();
+		const bool bUndo(pDoc->IsUndoEnabled());
+		const SCTAB nTab(GetTab_Impl());
 
-		ScPrintRangeSaver* pNewRanges = pDoc->CreatePrintRangeSaver();
-		if (bUndo)
+		if(bUndo)
 		{
-			pDocSh->GetUndoManager()->AddUndoAction(
-						new ScUndoPrintRange( pDocSh, nTab, pOldRanges, pNewRanges ) );
-		}
+            pDocSh->GetUndoManager()->AddUndoAction(
+			    new ScUndoPrintRange( 
+                    pDocSh, 
+                    nTab, 
+                    pOldRanges,
+                    pDoc->CreatePrintRangeSaver())); // create new ranges
 
-		ScPrintFunc( pDocSh, pDocSh->GetPrinter(), nTab ).UpdatePages();
+            // #120105# ownership of old ranges has changed, mark as consumed
+            pOldRanges = 0;
+		}
 
+		ScPrintFunc(pDocSh, pDocSh->GetPrinter(), nTab).UpdatePages();
 		SfxBindings* pBindings = pDocSh->GetViewBindings();
-		if (pBindings)
-			pBindings->Invalidate( SID_DELETE_PRINTAREA );
+
+        if(pBindings)
+        {
+			pBindings->Invalidate(SID_DELETE_PRINTAREA);
+        }
 
 		pDocSh->SetDocumentModified();
 	}
-	else
+
+    if(pOldRanges)
+    {
+        // #120105# pOldRanges not used, need to cleanup
 		delete pOldRanges;
+    }
 }
 
 uno::Sequence<table::CellRangeAddress> SAL_CALL ScTableSheetObj::getPrintAreas()