update ooo310-m15
[ooovba.git] / applied_patches / 0411-read-vba-dir-stream-fix.diff
blob2a99b6322688a6d03f80dcf3e83488205be177d8
1 diff --git svtools/inc/filterutils.hxx svtools/inc/filterutils.hxx
2 new file mode 100644
3 index 0000000..a05025f
4 --- /dev/null
5 +++ svtools/inc/filterutils.hxx
6 @@ -0,0 +1,22 @@
7 +#ifndef SVTOOLS_INC_FILTERUTILS_HXX
8 +#define SVTOOLS_INC_FILTERUTILS_HXX
10 +#include "svtools/svtdllapi.h"
11 +#include <com/sun/star/uno/RuntimeException.hpp>
12 +namespace svt
14 + class BinFilterUtils
15 + {
16 + private:
17 + BinFilterUtils(); // never implemented
19 + public:
20 + SVT_DLLPUBLIC static rtl::OUString CreateOUStringFromUniStringArray( const char* pcCharArr, sal_uInt32 nBufSize );
21 + SVT_DLLPUBLIC static rtl::OUString CreateOUStringFromStringArray( const char* pcCharArr, sal_uInt32 nBufSize );
22 + };
24 +//........................................................................
25 +} // namespace svt
26 +//........................................................................
28 +#endif
29 diff --git svtools/prj/d.lst svtools/prj/d.lst
30 index d0a7a98..7757b38 100644
31 --- svtools/prj/d.lst
32 +++ svtools/prj/d.lst
33 @@ -173,6 +173,7 @@ mkdir: %_DEST%\inc%_EXT%\svtools
34 ..\inc\svtools\httpcook.hxx %_DEST%\inc%_EXT%\svtools\httpcook.hxx
35 ..\inc\imageresourceaccess.hxx %_DEST%\inc%_EXT%\svtools\imageresourceaccess.hxx
36 ..\inc\bindablecontrolhelper.hxx %_DEST%\inc%_EXT%\svtools\bindablecontrolhelper.hxx
37 +..\inc\filterutils.hxx %_DEST%\inc%_EXT%\svtools\filterutils.hxx
38 ..\inc\svtools\itemprop.hxx %_DEST%\inc%_EXT%\svtools\itemprop.hxx
39 ..\inc\addresstemplate.hxx %_DEST%\inc%_EXT%\svtools\addresstemplate.hxx
40 ..\inc\svtools\genericunodialog.hxx %_DEST%\inc%_EXT%\svtools\genericunodialog.hxx
41 diff --git svtools/source/misc/filterutils.cxx svtools/source/misc/filterutils.cxx
42 new file mode 100644
43 index 0000000..91a6ca4
44 --- /dev/null
45 +++ svtools/source/misc/filterutils.cxx
46 @@ -0,0 +1,56 @@
47 +// MARKER(update_precomp.py): autogen include statement, do not remove
48 +#include "precompiled_svtools.hxx"
49 +#include "filterutils.hxx"
50 +#include <rtl/ustrbuf.hxx>
52 +namespace svt
54 +//........................................................................
56 + using namespace ::com::sun::star;
58 + rtl::OUString lcl_createStringFromArray( const char* pcCharArr, sal_uInt32 nBufSize, bool bIsCompressed )
59 + {
60 + rtl::OUStringBuffer aBuffer;
61 + if( bIsCompressed )
62 + {
63 + // buffer contains compressed Unicode, not encoded bytestring
64 + sal_Int32 nStrLen = static_cast< sal_Int32 >( nBufSize );
65 + aBuffer.setLength( nStrLen );
66 + const char* pcCurrChar = pcCharArr;
67 + for( sal_Int32 nChar = 0; nChar < nStrLen; ++nChar, ++pcCurrChar )
68 + /* *pcCurrChar may contain negative values and therefore MUST be
69 + casted to unsigned char, before assigned to a sal_Unicode. */
70 + aBuffer.setCharAt( nChar, static_cast< unsigned char >( *pcCurrChar ) );
71 + }
72 + else
73 + {
74 + // buffer contains Little-Endian Unicode
75 + sal_Int32 nStrLen = static_cast< sal_Int32 >( nBufSize ) / 2;
76 + aBuffer.setLength( nStrLen );
77 + const char* pcCurrChar = pcCharArr;
78 + for( sal_Int32 nChar = 0; nChar < nStrLen; ++nChar )
79 + {
80 + /* *pcCurrChar may contain negative values and therefore MUST be
81 + casted to unsigned char, before assigned to a sal_Unicode. */
82 + sal_Unicode cChar = static_cast< unsigned char >( *pcCurrChar++ );
83 + cChar |= (static_cast< unsigned char >( *pcCurrChar++ ) << 8);
84 + aBuffer.setCharAt( nChar, cChar );
85 + }
86 + }
87 + return aBuffer.makeStringAndClear();
88 + }
90 + rtl::OUString BinFilterUtils::CreateOUStringFromUniStringArray( const char* pcCharArr, sal_uInt32 nBufSize )
91 + {
92 + return lcl_createStringFromArray( pcCharArr, nBufSize, false );
93 + }
95 + rtl::OUString BinFilterUtils::CreateOUStringFromStringArray( const char* pcCharArr, sal_uInt32 nBufSize )
96 + {
97 + return lcl_createStringFromArray( pcCharArr, nBufSize, true );
98 + }
99 +//........................................................................
100 +} // namespace svt
101 +//........................................................................
103 diff --git svtools/source/misc/makefile.mk svtools/source/misc/makefile.mk
104 index 58943ad..e78ee40 100644
105 --- svtools/source/misc/makefile.mk
106 +++ svtools/source/misc/makefile.mk
107 @@ -86,6 +86,7 @@ SLOFILES=\
108 $(SLO)$/sharecontrolfile.obj \
109 $(SLO)$/documentlockfile.obj \
110 $(SLO)$/bindablecontrolhelper.obj \
111 + $(SLO)$/filterutils.obj \
112 $(SLO)$/langtab.obj
114 # --- Targets -------------------------------------------------------
115 diff --git svx/source/msfilter/msocximex.cxx svx/source/msfilter/msocximex.cxx
116 index c4f61b3..598e0ea 100644
117 --- svx/source/msfilter/msocximex.cxx
118 +++ svx/source/msfilter/msocximex.cxx
119 @@ -97,6 +97,7 @@
120 #include <com/sun/star/sheet/XSpreadsheetView.hpp>
121 #include <com/sun/star/sheet/XCellRangeAddressable.hpp>
122 #include <com/sun/star/sheet/XCellRangeReferrer.hpp>
123 +#include <svtools/filterutils.hxx>
125 #ifndef C2S
126 #define C2S(cChar) String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM(cChar))
127 @@ -354,35 +355,11 @@ void lclReadCharArray( SvStorageStream& rStrm, char*& rpcCharArr, sal_uInt32 nLe
129 OUString lclCreateOUString( const char* pcCharArr, sal_uInt32 nLenFld )
131 - OUStringBuffer aBuffer;
132 sal_uInt32 nBufSize = lclGetBufferSize( nLenFld );
133 if( lclIsCompressed( nLenFld ) )
135 - // buffer contains compressed Unicode, not encoded bytestring
136 - sal_Int32 nStrLen = static_cast< sal_Int32 >( nBufSize );
137 - aBuffer.setLength( nStrLen );
138 - const char* pcCurrChar = pcCharArr;
139 - for( sal_Int32 nChar = 0; nChar < nStrLen; ++nChar, ++pcCurrChar )
140 - /* *pcCurrChar may contain negative values and therefore MUST be
141 - casted to unsigned char, before assigned to a sal_Unicode. */
142 - aBuffer.setCharAt( nChar, static_cast< unsigned char >( *pcCurrChar ) );
144 - else
146 - // buffer contains Little-Endian Unicode
147 - sal_Int32 nStrLen = static_cast< sal_Int32 >( nBufSize ) / 2;
148 - aBuffer.setLength( nStrLen );
149 - const char* pcCurrChar = pcCharArr;
150 - for( sal_Int32 nChar = 0; nChar < nStrLen; ++nChar )
152 - /* *pcCurrChar may contain negative values and therefore MUST be
153 - casted to unsigned char, before assigned to a sal_Unicode. */
154 - sal_Unicode cChar = static_cast< unsigned char >( *pcCurrChar++ );
155 - cChar |= (static_cast< unsigned char >( *pcCurrChar++ ) << 8);
156 - aBuffer.setCharAt( nChar, cChar );
159 - return aBuffer.makeStringAndClear();
160 + return svt::BinFilterUtils::CreateOUStringFromStringArray( pcCharArr, nBufSize );
162 + return svt::BinFilterUtils::CreateOUStringFromUniStringArray( pcCharArr, nBufSize );
165 // export ---------------------------------------------------------------------
166 diff --git svx/source/msfilter/mstoolbar.cxx svx/source/msfilter/mstoolbar.cxx
167 index 6e1dec0..2647c58 100644
168 --- svx/source/msfilter/mstoolbar.cxx
169 +++ svx/source/msfilter/mstoolbar.cxx
170 @@ -10,6 +10,8 @@
171 #include <map>
172 #include <sfx2/objsh.hxx>
173 #include <basic/basmgr.hxx>
174 +#include <svtools/filterutils.hxx>
175 +#include <boost/scoped_array.hpp>
177 int TBBase::nIndent = 0;
179 @@ -26,7 +28,10 @@ void CustomToolBarImportHelper::applyIcons()
180 uno::Reference< ui::XImageManager > xImageManager( getCfgManager()->getImageManager(), uno::UNO_QUERY_THROW );
181 // 1 seems to work best for MSO images, otherwise they don't get displayed ( I guess the default size
182 // in ooo is different )
183 - xImageManager->insertImages( 1, commands, images );
184 + //xImageManager->insertImages( 1, commands, images ); // #FIXME and scale images based on default icon size
185 + xImageManager->replaceImages( 1, commands, images );
186 + xImageManager->replaceImages( 2, commands, images );
187 + xImageManager->replaceImages( 3, commands, images );
191 @@ -107,15 +112,10 @@ TBBase::indent_printf( FILE* fp, const char* format, ... )
193 rtl::OUString TBBase::readUnicodeString( SvStream* pS, sal_Int32 nChars )
195 - rtl::OUStringBuffer buf(40);
196 - for ( sal_Int32 index = 0; index < nChars; ++index )
198 - sal_uInt16 ch = 0;
199 - *pS >> ch;
200 - sal_Unicode uni = static_cast< sal_Unicode >( ch );
201 - buf.append( &uni, 1 );
203 - return buf.makeStringAndClear();
204 + sal_Int32 nBufSize = nChars * 2;
205 + boost::scoped_array< sal_uInt8 > pArray( new sal_uInt8[ nBufSize ] );
206 + pS->Read( pArray.get(), nBufSize );
207 + return svt::BinFilterUtils::CreateOUStringFromUniStringArray( reinterpret_cast< const char* >( pArray.get() ), nBufSize );
210 TBCHeader::TBCHeader() : bSignature( 0x3 )
211 diff --git svx/source/msfilter/msvbasic.cxx svx/source/msfilter/msvbasic.cxx
212 index a8aac8a..e040862 100644
213 --- svx/source/msfilter/msvbasic.cxx
214 +++ svx/source/msfilter/msvbasic.cxx
215 @@ -43,79 +43,13 @@
216 #include <fstream>
217 #include <memory>
218 #include <rtl/ustrbuf.hxx>
219 +#include <boost/shared_ptr.hpp>
220 +#include <boost/scoped_array.hpp>
221 +#include <boost/shared_array.hpp>
222 +#include <svtools/filterutils.hxx>
224 using namespace ::com::sun::star::script;
226 -// #FIXME this routine is stolen from msocximex ( needs to be somewhere central )
228 -const sal_uInt32 SVX_MSOCX_SIZEMASK = 0x7FFFFFFF; /// Mask for character buffer size.
229 -const sal_uInt32 SVX_MSOCX_COMPRESSED = 0x80000000;
231 -inline bool lclIsCompressed( sal_uInt32 nLenFld )
233 - return (nLenFld & SVX_MSOCX_COMPRESSED) != 0;
237 -/** Extracts and returns the memory size of the character buffer.
238 - @return Character buffer size (may differ from resulting string length!).
239 - */
240 -inline sal_uInt32 lclGetBufferSize( sal_uInt32 nLenFld )
242 - return nLenFld & SVX_MSOCX_SIZEMASK;
244 -/** Creates an OUString from a character array created with lclReadCharArray().
246 - The passed parameters must match, that means the length field must be the
247 - same used to create the passed character array.
249 - @param pcCharArr
250 - The character array returned by lclReadCharArray(). May be compressed
251 - or uncompressed, next parameter nLenFld will specify this.
253 - @param nLenFld
254 - MUST be the same string length field that has been passed to
255 - lclReadCharArray() to create the character array in previous parameter
256 - pcCharArr.
258 - @return
259 - An OUString containing the decoded string data. Will be empty if
260 - pcCharArr is 0.
261 - */
262 -rtl::OUString lclCreateOUString( const char* pcCharArr, sal_uInt32 nLenFld )
264 - rtl::OUStringBuffer aBuffer;
265 - sal_uInt32 nBufSize = lclGetBufferSize( nLenFld );
266 - if( lclIsCompressed( nLenFld ) )
268 - // buffer contains compressed Unicode, not encoded bytestring
269 - sal_Int32 nStrLen = static_cast< sal_Int32 >( nBufSize );
270 - aBuffer.setLength( nStrLen );
271 - const char* pcCurrChar = pcCharArr;
272 - for( sal_Int32 nChar = 0; nChar < nStrLen; ++nChar, ++pcCurrChar )
273 - /* *pcCurrChar may contain negative values and therefore MUST be
274 - casted to unsigned char, before assigned to a sal_Unicode. */
275 - aBuffer.setCharAt( nChar, static_cast< unsigned char >( *pcCurrChar ) );
277 - else
279 - // buffer contains Little-Endian Unicode
280 - sal_Int32 nStrLen = static_cast< sal_Int32 >( nBufSize ) / 2;
281 - aBuffer.setLength( nStrLen );
282 - const char* pcCurrChar = pcCharArr;
283 - for( sal_Int32 nChar = 0; nChar < nStrLen; ++nChar )
285 - /* *pcCurrChar may contain negative values and therefore MUST be
286 - casted to unsigned char, before assigned to a sal_Unicode. */
287 - sal_Unicode cChar = static_cast< unsigned char >( *pcCurrChar++ );
288 - cChar |= (static_cast< unsigned char >( *pcCurrChar++ ) << 8);
289 - aBuffer.setCharAt( nChar, cChar );
292 - return aBuffer.makeStringAndClear();
296 namespace MSLZSS {
298 static unsigned int getShift( sal_uInt32 nPos )
299 @@ -238,23 +172,21 @@ sal_Int16 Reserved1;
300 sal_Int16 Version;
301 sal_Int8 Reserved2;
302 sal_Int16 Reserved3;
303 -sal_uInt8* PerformanceCache;
304 +boost::scoped_array< sal_uInt8 > PerformanceCache;
305 sal_Int32 PerformanceCacheSize;
306 -_VBA_PROJECT_VDPI(): Reserved1( 0x61CC), Version( 0xFFFF ), Reserved2(0x0), Reserved3(0x0), PerformanceCache(0), PerformanceCacheSize(0) {}
307 +_VBA_PROJECT_VDPI(): Reserved1( 0x61CC), Version( 0xFFFF ), Reserved2(0x0), Reserved3(0x0), PerformanceCacheSize(0) {}
308 ~_VBA_PROJECT_VDPI()
310 - if ( PerformanceCache )
311 - delete [] PerformanceCache;
312 - PerformanceCache = 0;
313 PerformanceCacheSize = 0;
315 void read(){}
316 void write( SvStream* pStream )
318 *pStream << Reserved1 << Version << Reserved2 << Reserved3;
319 - for( sal_Int32 i = 0; PerformanceCache && i < PerformanceCacheSize; ++i )
320 + if ( PerformanceCacheSize )
322 - *pStream >> PerformanceCache[ i ];
323 + PerformanceCache.reset( new sal_uInt8[ PerformanceCacheSize ] );
324 + pStream->Read( PerformanceCache.get(), PerformanceCacheSize );
328 @@ -320,27 +252,22 @@ class ProjectNameRecord
329 public:
330 sal_Int16 Id;
331 sal_Int32 SizeOfProjectName;
332 -sal_uInt8* ProjectName;
333 -rtl::OUString msProjectName;
334 -ProjectNameRecord() : Id( 0x04 ), SizeOfProjectName( 0x0 ), ProjectName(0) {}
335 +rtl::OUString ProjectName;
336 +ProjectNameRecord() : Id( 0x04 ), SizeOfProjectName( 0x0 ){}
337 ~ProjectNameRecord()
339 - delete [] ProjectName;
340 - ProjectName = 0;
342 void read( SvStream* pStream )
344 OSL_TRACE("ProjectNameRecord [0x%x]", pStream->Tell() );
345 *pStream >> Id >> SizeOfProjectName;
346 - if ( ProjectName )
347 - delete [] ProjectName;
349 if ( SizeOfProjectName )
351 - ProjectName = new sal_uInt8[ SizeOfProjectName ];
352 + boost::scoped_array< sal_uInt8 > pProjectName( new sal_uInt8[ SizeOfProjectName ] );
353 OSL_TRACE("ProjectNameRecord about to read name from [0x%x], size %d", pStream->Tell(), SizeOfProjectName );
354 - pStream->Read( ProjectName, SizeOfProjectName );
355 - msProjectName = lclCreateOUString( reinterpret_cast< const char* >( ProjectName ), ( SVX_MSOCX_COMPRESSED | SizeOfProjectName ) );
356 + pStream->Read( pProjectName.get(), SizeOfProjectName );
357 + ProjectName = svt::BinFilterUtils::CreateOUStringFromStringArray( reinterpret_cast< const char* >( pProjectName.get() ), SizeOfProjectName );
361 @@ -350,42 +277,34 @@ class ProjectDocStringRecord
362 public:
363 sal_Int16 Id;
364 sal_Int32 SizeOfDocString;
365 -sal_uInt8* DocString;
366 sal_Int16 Reserved;
367 sal_Int32 SizeOfDocStringUnicode;
368 -sal_uInt8* DocStringUnicode;
369 +rtl::OUString DocString;
370 +rtl::OUString DocStringUnicode;
372 -ProjectDocStringRecord() : Id( 0x5 ), SizeOfDocString( 0x0 ), DocString( 0 ), Reserved( 0x0 ), SizeOfDocStringUnicode( 0 ), DocStringUnicode( 0 ) {}
373 +ProjectDocStringRecord() : Id( 0x5 ), SizeOfDocString( 0x0 ), Reserved( 0x0 ), SizeOfDocStringUnicode( 0 ){}
375 ~ProjectDocStringRecord()
377 - delete [] DocString;
378 - delete [] DocStringUnicode;
379 - DocString = 0;
380 - DocStringUnicode = 0;
382 void read( SvStream* pStream )
384 OSL_TRACE("ProjectDocStringRecord [0x%x]", pStream->Tell() );
385 *pStream >> Id >> SizeOfDocString;
387 - if ( DocString )
388 - delete [] DocString;
390 - DocString = new sal_uInt8[ SizeOfDocString ];
391 - pStream->Read( DocString, SizeOfDocString );
393 - if ( SizeOfDocStringUnicode )
394 - delete [] DocStringUnicode;
395 + boost::scoped_array< sal_uInt8 > pDocString( new sal_uInt8[ SizeOfDocString ] );
396 + pStream->Read( pDocString.get(), SizeOfDocString );
398 + DocString = svt::BinFilterUtils::CreateOUStringFromStringArray( reinterpret_cast< const char* >( pDocString.get() ), SizeOfDocString );
400 *pStream >> Reserved >> SizeOfDocStringUnicode;
402 - if ( DocStringUnicode )
403 - delete [] DocStringUnicode;
404 + boost::scoped_array< sal_uInt8 > pDocStringUnicode( new sal_uInt8[ SizeOfDocStringUnicode ] );
406 - DocStringUnicode = new sal_uInt8[ SizeOfDocStringUnicode ];
407 + pStream->Read( pDocStringUnicode.get(), SizeOfDocStringUnicode );
408 + DocStringUnicode = svt::BinFilterUtils::CreateOUStringFromUniStringArray( reinterpret_cast< const char* >( pDocStringUnicode.get() ), SizeOfDocString );
410 - pStream->Read( DocStringUnicode, SizeOfDocStringUnicode );
414 @@ -395,39 +314,28 @@ class ProjectHelpFilePath
415 public:
416 sal_Int16 Id;
417 sal_Int32 SizeOfHelpFile1;
418 -sal_uInt8* HelpFile1;
419 +boost::scoped_array< sal_uInt8 > HelpFile1;
420 sal_Int16 Reserved;
421 sal_Int32 SizeOfHelpFile2;
422 -sal_uInt8* HelpFile2;
423 +boost::scoped_array< sal_uInt8 > HelpFile2;
425 -ProjectHelpFilePath() : Id( 0x06 ), SizeOfHelpFile1(0), HelpFile1(0), Reserved(0x0), SizeOfHelpFile2(0), HelpFile2(0) {}
426 +ProjectHelpFilePath() : Id( 0x06 ), SizeOfHelpFile1(0), Reserved(0x0), SizeOfHelpFile2(0) {}
427 ~ProjectHelpFilePath()
429 - if ( HelpFile1 )
430 - delete [] HelpFile1;
431 - if ( HelpFile2 )
432 - delete [] HelpFile2;
433 - HelpFile1 = 0;
434 - HelpFile2 = 0;
437 void read( SvStream* pStream )
439 OSL_TRACE("ProjectHelpFilePath [0x%x]", pStream->Tell() );
440 *pStream >> Id >> SizeOfHelpFile1;
442 - if ( HelpFile1 )
443 - delete HelpFile1;
445 - HelpFile1 = new sal_uInt8[ SizeOfHelpFile1 ];
446 - pStream->Read( HelpFile1, SizeOfHelpFile1 );
447 + HelpFile1.reset( new sal_uInt8[ SizeOfHelpFile1 ] );
448 + pStream->Read( HelpFile1.get(), SizeOfHelpFile1 );
450 *pStream >> Reserved >> SizeOfHelpFile2;
452 - if ( HelpFile2 )
453 - delete HelpFile2;
455 - HelpFile2 = new sal_uInt8[ SizeOfHelpFile2 ];
456 - pStream->Read( HelpFile2, SizeOfHelpFile2 );
457 + HelpFile2.reset( new sal_uInt8[ SizeOfHelpFile2 ] );
458 + pStream->Read( HelpFile2.get(), SizeOfHelpFile2 );
462 @@ -483,40 +391,31 @@ class ProjectConstantsRecord
464 sal_Int16 Id;
465 sal_Int32 SizeOfConstants;
466 -sal_uInt8* Constants;
467 +boost::scoped_array< sal_uInt8 > Constants;
468 sal_Int16 Reserved;
469 sal_Int32 SizeOfConstantsUnicode;
470 -sal_uInt8* ConstantsUnicode;
471 +boost::scoped_array< sal_uInt8 > ConstantsUnicode;
472 public:
473 ProjectConstantsRecord() : Id( 0xC ), SizeOfConstants( 0 ), Constants( 0 ), Reserved( 0x3C ), SizeOfConstantsUnicode( 0 ), ConstantsUnicode(0) {}
475 ~ProjectConstantsRecord()
477 - delete [] Constants;
478 - Constants = 0;
479 - delete [] ConstantsUnicode;
480 - ConstantsUnicode = 0;
483 void read( SvStream* pStream )
485 OSL_TRACE("ProjectConstantsRecord [0x%x]", pStream->Tell() );
486 *pStream >> Id >> SizeOfConstants;
487 - if ( Constants )
488 - delete [] Constants;
489 - Constants = new sal_uInt8[ SizeOfConstants ];
490 + Constants.reset( new sal_uInt8[ SizeOfConstants ] );
492 - pStream->Read( Constants, SizeOfConstants );
493 + pStream->Read( Constants.get(), SizeOfConstants );
495 *pStream >> Reserved;
497 - if ( ConstantsUnicode )
498 - delete [] ConstantsUnicode;
500 *pStream >> SizeOfConstantsUnicode;
502 - ConstantsUnicode = new sal_uInt8[ SizeOfConstantsUnicode ];
503 - pStream->Read( ConstantsUnicode, SizeOfConstantsUnicode );
504 + ConstantsUnicode.reset( new sal_uInt8[ SizeOfConstantsUnicode ] );
505 + pStream->Read( ConstantsUnicode.get(), SizeOfConstantsUnicode );
509 @@ -526,18 +425,14 @@ class ReferenceNameRecord
510 public:
511 sal_Int16 Id;
512 sal_Int32 SizeOfName;
513 -sal_uInt8* Name;
514 +rtl::OUString Name;
515 sal_Int16 Reserved;
516 sal_Int32 SizeOfNameUnicode;
517 -sal_uInt8* NameUnicode;
518 +rtl::OUString NameUnicode;
520 -ReferenceNameRecord() : Id( 0x16 ), SizeOfName( 0 ), Name( 0 ), Reserved( 0x3E ), SizeOfNameUnicode( 0 ), NameUnicode( 0 ) {}
521 +ReferenceNameRecord() : Id( 0x16 ), SizeOfName( 0 ), Reserved( 0x3E ), SizeOfNameUnicode( 0 ){}
522 ~ReferenceNameRecord()
524 - delete [] Name;
525 - Name = 0;
526 - delete [] NameUnicode;
527 - NameUnicode = 0;
530 void read( SvStream* pStream )
531 @@ -545,20 +440,16 @@ void read( SvStream* pStream )
532 OSL_TRACE("NameRecord [0x%x]", pStream->Tell() );
533 *pStream >> Id >> SizeOfName;
535 - if ( Name )
536 - delete [] Name;
537 + boost::scoped_array< sal_uInt8 > pName( new sal_uInt8[ SizeOfName ] );
539 - Name = new sal_uInt8[ SizeOfName ];
541 - pStream->Read( Name, SizeOfName );
542 + pStream->Read( pName.get(), SizeOfName );
543 + Name = svt::BinFilterUtils::CreateOUStringFromStringArray( reinterpret_cast< const char* >( pName.get() ), SizeOfName );
545 *pStream >> Reserved >> SizeOfNameUnicode;
547 - if ( NameUnicode )
548 - delete [] Name;
550 - NameUnicode = new sal_uInt8[ SizeOfNameUnicode ];
551 - pStream->Read( NameUnicode, SizeOfNameUnicode );
552 + boost::scoped_array< sal_uInt8 > pNameUnicode( new sal_uInt8[ SizeOfNameUnicode ] );
553 + pStream->Read( pNameUnicode.get(), SizeOfNameUnicode );
554 + NameUnicode = svt::BinFilterUtils::CreateOUStringFromUniStringArray( reinterpret_cast< const char* >( pNameUnicode.get() ), SizeOfName );
558 @@ -581,13 +472,11 @@ public:
559 sal_uInt16 Id;
560 sal_uInt32 Size;
561 sal_uInt32 SizeOfLibidAbsolute;
562 - sal_uInt8* pLibidAbsolute;
563 sal_uInt32 SizeOfLibidRelative;
564 - sal_uInt8* pLibidRelative;
565 sal_uInt32 MajorVersion;
566 sal_uInt16 MinorVersion;
567 - rtl::OUString msAbsoluteLibid;
568 - rtl::OUString msRelativeLibid;
569 + rtl::OUString AbsoluteLibid;
570 + rtl::OUString RelativeLibid;
572 virtual bool read( SvStream* pStream );
573 virtual void import( VBA_Impl& rDir );
574 @@ -595,16 +484,12 @@ public:
575 ~ReferenceProjectRecord();
578 -ReferenceProjectRecord::ReferenceProjectRecord() : Id( 0x000E ), Size( 0 ), SizeOfLibidAbsolute( 0 ), pLibidAbsolute( NULL ), SizeOfLibidRelative( 0 ), pLibidRelative( 0 ), MajorVersion( 0 ), MinorVersion( 0 )
579 +ReferenceProjectRecord::ReferenceProjectRecord() : Id( 0x000E ), Size( 0 ), SizeOfLibidAbsolute( 0 ), SizeOfLibidRelative( 0 ), MajorVersion( 0 ), MinorVersion( 0 )
583 ReferenceProjectRecord::~ReferenceProjectRecord()
585 - if ( pLibidAbsolute )
586 - delete[] pLibidAbsolute;
587 - if ( pLibidRelative )
588 - delete[] pLibidRelative;
591 bool ReferenceProjectRecord::read( SvStream* pStream )
592 @@ -612,21 +497,15 @@ bool ReferenceProjectRecord::read( SvStream* pStream )
593 OSL_TRACE("ReferenceProjectRecord [0x%x]", pStream->Tell() );
594 *pStream >> Id >> Size >> SizeOfLibidAbsolute;
596 - if ( SizeOfLibidAbsolute )
598 - pLibidAbsolute = new sal_uInt8[ SizeOfLibidAbsolute ];
599 - OSL_TRACE("ReferenceProjectRecord about to read LibidAbsolute at [0x%x]", pStream->Tell() );
600 - pStream->Read( pLibidAbsolute, SizeOfLibidAbsolute );
602 + boost::scoped_array< sal_uInt8 > pLibidAbsolute( new sal_uInt8[ SizeOfLibidAbsolute ] );
603 + OSL_TRACE("ReferenceProjectRecord about to read LibidAbsolute at [0x%x]", pStream->Tell() );
604 + pStream->Read( pLibidAbsolute.get(), SizeOfLibidAbsolute );
606 *pStream >> SizeOfLibidRelative;
608 - if ( SizeOfLibidRelative )
610 - pLibidRelative = new sal_uInt8[ SizeOfLibidRelative ];
611 - OSL_TRACE("ReferenceProjectRecord about to read LibidRelative at [0x%x]", pStream->Tell() );
612 - pStream->Read( pLibidRelative, SizeOfLibidRelative );
614 + boost::scoped_array< sal_uInt8 > pLibidRelative( new sal_uInt8[ SizeOfLibidRelative ] );
615 + OSL_TRACE("ReferenceProjectRecord about to read LibidRelative at [0x%x]", pStream->Tell() );
616 + pStream->Read( pLibidRelative.get(), SizeOfLibidRelative );
618 *pStream >> MajorVersion >> MinorVersion;
620 @@ -634,17 +513,17 @@ bool ReferenceProjectRecord::read( SvStream* pStream )
621 // 16 bit unicode )
622 // the offset of 3 is needed to skip the ProjectReference "*\" and project kind ( 0x4[1-4] ) info.
624 - msAbsoluteLibid = lclCreateOUString( reinterpret_cast< const char* >( pLibidAbsolute + 3 ), ( SVX_MSOCX_COMPRESSED | (SizeOfLibidAbsolute - 3 )));
625 - msRelativeLibid = lclCreateOUString( reinterpret_cast< const char* >( pLibidRelative + 3 ), ( SVX_MSOCX_COMPRESSED | ( SizeOfLibidRelative -3 )));
626 + AbsoluteLibid = svt::BinFilterUtils::CreateOUStringFromStringArray( reinterpret_cast< const char* >( pLibidAbsolute.get() + 3 ), (SizeOfLibidAbsolute - 3 ) );
627 + RelativeLibid = svt::BinFilterUtils::CreateOUStringFromStringArray( reinterpret_cast< const char* >( pLibidRelative.get() + 3 ), ( SizeOfLibidRelative -3 ) );
629 - OSL_TRACE("ReferenceProjectRecord - absolute path %s", rtl::OUStringToOString( msAbsoluteLibid, RTL_TEXTENCODING_UTF8 ).getStr() );
630 - OSL_TRACE("ReferenceProjectRecord - relative path %s", rtl::OUStringToOString( msRelativeLibid, RTL_TEXTENCODING_UTF8 ).getStr() );
631 + OSL_TRACE("ReferenceProjectRecord - absolute path %s", rtl::OUStringToOString( AbsoluteLibid, RTL_TEXTENCODING_UTF8 ).getStr() );
632 + OSL_TRACE("ReferenceProjectRecord - relative path %s", rtl::OUStringToOString( RelativeLibid, RTL_TEXTENCODING_UTF8 ).getStr() );
633 return true;
636 void ReferenceProjectRecord::import( VBA_Impl& rDir )
638 - rDir.AddProjectReference( msAbsoluteLibid );
639 + rDir.AddProjectReference( AbsoluteLibid );
642 class ReferenceRegisteredRecord : public BaseReferenceRecord
643 @@ -653,7 +532,7 @@ public:
644 sal_uInt16 Id;
645 sal_uInt32 Size;
646 sal_uInt32 SizeOfLibid;
647 - sal_uInt8* pLibid;
648 + boost::scoped_array< sal_uInt8> pLibid;
649 sal_Int32 Reserved1;
650 sal_Int16 Reserved2;
652 @@ -662,16 +541,12 @@ public:
653 bool read( SvStream* pStream );
656 -ReferenceRegisteredRecord::ReferenceRegisteredRecord() : Id( 0x000D ), Size( 0 ), SizeOfLibid( 0 ), pLibid( NULL ), Reserved1( 0 ), Reserved2( 0 )
657 +ReferenceRegisteredRecord::ReferenceRegisteredRecord() : Id( 0x000D ), Size( 0 ), SizeOfLibid( 0 ), Reserved1( 0 ), Reserved2( 0 )
661 ReferenceRegisteredRecord::~ReferenceRegisteredRecord()
663 - if ( pLibid )
665 - delete[] pLibid;
669 bool
670 @@ -681,9 +556,8 @@ ReferenceRegisteredRecord::read( SvStream* pStream )
671 *pStream >> Id >> Size >> SizeOfLibid;
672 if ( SizeOfLibid )
674 - pLibid = new sal_uInt8[ SizeOfLibid ];
675 - OSL_TRACE("ReferenceRegisteredRecord about to read Libid [0x%x]", pStream->Tell() );
676 - pStream->Read( pLibid, SizeOfLibid );
677 + pLibid.reset( new sal_uInt8[ SizeOfLibid] );
678 + pStream->Read( pLibid.get(), SizeOfLibid );
680 *pStream >> Reserved1 >> Reserved2;
681 return true;
682 @@ -694,17 +568,15 @@ class ReferenceOriginalRecord
683 public:
684 sal_uInt16 Id;
685 sal_uInt32 SizeOfLibOriginal;
686 - sal_uInt8* pLibidOriginal;
687 + boost::scoped_array< sal_uInt8 > pLibidOriginal;
690 -ReferenceOriginalRecord() : Id( 0x033 ), SizeOfLibOriginal( 0 ), pLibidOriginal( NULL )
691 +ReferenceOriginalRecord() : Id( 0x033 ), SizeOfLibOriginal( 0 )
695 ~ReferenceOriginalRecord()
697 - if ( pLibidOriginal )
698 - delete[] pLibidOriginal;
701 void read( SvStream* pStream )
702 @@ -712,8 +584,8 @@ void read( SvStream* pStream )
703 *pStream >> Id >> SizeOfLibOriginal;
704 if ( SizeOfLibOriginal )
706 - pLibidOriginal = new sal_uInt8[ SizeOfLibOriginal ];
707 - pStream->Read( pLibidOriginal, SizeOfLibOriginal );
708 + pLibidOriginal.reset( new sal_uInt8[ SizeOfLibOriginal ] );
709 + pStream->Read( pLibidOriginal.get(), SizeOfLibOriginal );
713 @@ -722,24 +594,24 @@ void read( SvStream* pStream )
714 class ReferenceControlRecord : public BaseReferenceRecord
716 public:
717 -ReferenceOriginalRecord OriginalRecord;
718 +std::auto_ptr< ReferenceOriginalRecord > OriginalRecord;
719 sal_Int16 Id;
720 sal_uInt32 SizeTwiddled;
721 sal_uInt32 SizeOfLibidTwiddled;
722 -sal_uInt8* LibidTwiddled;
723 +boost::shared_array< sal_uInt8 > LibidTwiddled;
724 sal_uInt32 Reserved1;
725 sal_uInt16 Reserved2;
726 -ReferenceNameRecord* NameRecordExtended;// Optional
727 +std::auto_ptr< ReferenceNameRecord > NameRecordExtended;// Optional
728 sal_uInt16 Reserved3;
729 sal_uInt32 SizeExtended;
730 sal_uInt32 SizeOfLibidExtended;
731 -sal_uInt8* LibidExtended;
732 +boost::shared_array< sal_uInt8 > LibidExtended;
733 sal_uInt32 Reserved4;
734 sal_uInt16 Reserved5;
735 sal_uInt8 OriginalTypeLib[ 16 ];
736 sal_uInt32 Cookie;
738 -ReferenceControlRecord() : Id( 0x2F ), SizeTwiddled( 0 ), SizeOfLibidTwiddled( 0 ), LibidTwiddled( 0 ), Reserved1( 0 ), Reserved2( 0 ), NameRecordExtended( 0 ), Reserved3( 0x30 ), SizeExtended( 0 ), SizeOfLibidExtended( 0 ), LibidExtended( 0 ), Reserved4( 0 ), Reserved5( 0 ), Cookie( 0 )
739 +ReferenceControlRecord() : Id( 0x2F ), SizeTwiddled( 0 ), SizeOfLibidTwiddled( 0 ), Reserved1( 0 ), Reserved2( 0 ), Reserved3( 0x30 ), SizeExtended( 0 ), SizeOfLibidExtended( 0 ), Reserved4( 0 ), Reserved5( 0 ), Cookie( 0 )
741 for( int i = 0; i < 16; ++i )
742 OriginalTypeLib[ i ] = 0;
743 @@ -747,29 +619,31 @@ ReferenceControlRecord() : Id( 0x2F ), SizeTwiddled( 0 ), SizeOfLibidTwiddled( 0
745 ~ReferenceControlRecord()
747 - delete LibidTwiddled;
748 - delete NameRecordExtended;
749 - delete [] LibidExtended;
750 - LibidTwiddled = 0;
751 - NameRecordExtended = 0;
752 - LibidExtended = 0;
755 bool read( SvStream* pStream )
757 OSL_TRACE("ReferenceControlRecord [0x%x]", pStream->Tell() );
758 - OriginalRecord.read( pStream );
759 + long nPos = pStream->Tell();
761 + *pStream >> Id;
762 + pStream->Seek( nPos ); // point before the peeked Id
763 + if ( Id == 0x33 ) // we have an OriginalRecord
765 + OriginalRecord.reset( new ReferenceOriginalRecord() );
766 + OriginalRecord->read( pStream );
768 *pStream >> Id >> SizeTwiddled >> SizeOfLibidTwiddled;
770 if ( SizeOfLibidTwiddled )
772 - LibidTwiddled = new sal_uInt8[ SizeOfLibidTwiddled ];
773 - pStream->Read( LibidTwiddled, SizeOfLibidTwiddled );
774 + LibidTwiddled.reset( new sal_uInt8[ SizeOfLibidTwiddled ] );
775 + pStream->Read( LibidTwiddled.get(), SizeOfLibidTwiddled );
778 *pStream >> Reserved1 >> Reserved2;
780 - long nPos = pStream->Tell();
781 + nPos = pStream->Tell();
782 // peek at the id for optional NameRecord
783 sal_Int16 nTmpId;
784 *pStream >> nTmpId;
785 @@ -780,7 +654,7 @@ bool read( SvStream* pStream )
786 else
788 pStream->Seek( nPos );
789 - NameRecordExtended = new ReferenceNameRecord();
790 + NameRecordExtended.reset( new ReferenceNameRecord() );
791 NameRecordExtended->read( pStream );
792 *pStream >> Reserved3;
794 @@ -788,8 +662,8 @@ bool read( SvStream* pStream )
796 if ( SizeExtended )
798 - LibidExtended = new sal_uInt8[ SizeOfLibidExtended ];
799 - pStream->Read( LibidExtended, SizeOfLibidExtended );
800 + LibidExtended.reset( new sal_uInt8[ SizeOfLibidExtended ] );
801 + pStream->Read( LibidExtended.get(), SizeOfLibidExtended );
804 *pStream >> Reserved4;
805 @@ -806,15 +680,12 @@ class ReferenceRecord : public BaseReferenceRecord
807 public:
808 // NameRecord is Optional
809 -ReferenceNameRecord* NameRecord;
810 -BaseReferenceRecord* aReferenceRecord;
811 -ReferenceRecord(): NameRecord(0), aReferenceRecord(0) {}
812 +std::auto_ptr< ReferenceNameRecord > NameRecord;
813 +std::auto_ptr< BaseReferenceRecord > aReferenceRecord;
815 +ReferenceRecord(){}
816 ~ReferenceRecord()
818 - if ( NameRecord )
819 - delete NameRecord;
820 - if ( aReferenceRecord )
821 - delete aReferenceRecord;
824 // false return would mean failed to read Record e.g. end of array encountered
825 @@ -833,7 +704,7 @@ bool read( SvStream* pStream )
826 pStream->Seek( nPos ); // place back before Id
827 if ( Id == 0x16 ) // Optional NameRecord
829 - NameRecord = new ReferenceNameRecord();
830 + NameRecord.reset( new ReferenceNameRecord() );
831 NameRecord->read( pStream );
833 else if ( Id == 0x0f )
834 @@ -850,14 +721,14 @@ bool read( SvStream* pStream )
835 switch( Id )
837 case 0x0D:
838 - aReferenceRecord = new ReferenceRegisteredRecord();
839 + aReferenceRecord.reset( new ReferenceRegisteredRecord() );
840 break;
841 case 0x0E:
842 - aReferenceRecord = new ReferenceProjectRecord();
843 + aReferenceRecord.reset( new ReferenceProjectRecord() );
844 break;
845 case 0x2F:
846 case 0x33:
847 - aReferenceRecord = new ReferenceControlRecord();
848 + aReferenceRecord.reset( new ReferenceControlRecord() );
849 break;
850 default:
851 bRead = false;
852 @@ -871,7 +742,7 @@ bool read( SvStream* pStream )
854 void import( VBA_Impl& rVBA )
856 - if ( aReferenceRecord )
857 + if ( aReferenceRecord.get() )
858 aReferenceRecord->import( rVBA );
861 @@ -904,6 +775,7 @@ DirDumper() {}
862 void read( SvStream* pStream )
864 sal_Int32 nPos = pStream->Tell();
865 +#ifdef DEBUG
866 std::ofstream aDump("dir.dump");
867 while ( !pStream->IsEof() )
869 @@ -912,6 +784,7 @@ void read( SvStream* pStream )
870 aDump << aByte;
872 aDump.flush();
873 +#endif
874 pStream->Seek( nPos );
875 readProjectInformation( pStream );
876 readProjectReferenceInformation( pStream );
877 @@ -957,7 +830,7 @@ void import( VBA_Impl& rVBA )
878 // get project references
879 for ( std::vector< ReferenceRecord* >::iterator it = ReferenceArray.begin(); it != ReferenceArray.end(); ++it )
880 (*it)->import( rVBA );
881 - rVBA.SetProjectName( mProjectNameRec.msProjectName );
882 + rVBA.SetProjectName( mProjectNameRec.ProjectName );