[Libreoffice-commits] core.git: include/oox

David Tardon dtardon at redhat.com
Mon Oct 27 08:32:19 PDT 2014


 include/oox/helper/binaryoutputstream.hxx |   14 ++++++++++++++
 1 file changed, 14 insertions(+)

New commits:
commit f70db32aa2df79cca42c44f05baf4baac6e04bf5
Author: David Tardon <dtardon at redhat.com>
Date:   Mon Oct 27 16:12:43 2014 +0100

    fix writing const arrays on big endian
    
    Btw, th unanounced byte-swapping of valuse in the input array in
    writeArray seems a bit dubious to me... It could too easily cause
    unintentional memory damage. I just hope it is always called either with
    data that is not used after that anymore or with a copy of the data.
    
    Change-Id: Ica0e9ea16cd101fe87d7e0a8fa696911769e0654

diff --git a/include/oox/helper/binaryoutputstream.hxx b/include/oox/helper/binaryoutputstream.hxx
index 7f3ee73..4ccc585 100644
--- a/include/oox/helper/binaryoutputstream.hxx
+++ b/include/oox/helper/binaryoutputstream.hxx
@@ -20,6 +20,9 @@
 #ifndef INCLUDED_OOX_HELPER_BINARYOUTPUTSTREAM_HXX
 #define INCLUDED_OOX_HELPER_BINARYOUTPUTSTREAM_HXX
 
+#include <memory>
+#include <boost/shared_array.hpp>
+
 #include <oox/helper/binarystreambase.hxx>
 
 namespace com { namespace sun { namespace star {
@@ -64,6 +67,9 @@ public:
     template< typename Type >
     void writeArray( Type* opnArray, sal_Int32 nElemCount );
 
+    template< typename Type >
+    void writeArray( const Type* opnArray, sal_Int32 nElemCount );
+
     /** Stream operator for all data types supported by the writeValue() function. */
     template< typename Type >
     BinaryOutputStream& operator<<( Type nValue ) { writeValue( nValue ); return *this; }
@@ -88,6 +94,14 @@ void BinaryOutputStream::writeArray( Type* opnArray, sal_Int32 nElemCount )
     writeMemory( opnArray, nWriteSize, sizeof( Type ) );
 }
 
+template< typename Type >
+void BinaryOutputStream::writeArray( const Type* opnArray, sal_Int32 nElemCount )
+{
+    boost::shared_array<Type> pArray(new Type[nElemCount]);
+    std::uninitialized_copy(opnArray, opnArray + nElemCount, pArray.get());
+    writeArray(pArray.get(), nElemCount);
+}
+
 typedef ::boost::shared_ptr< BinaryOutputStream > BinaryOutputStreamRef;
 
 


More information about the Libreoffice-commits mailing list