[Libreoffice-commits] core.git: 4 commits - hwpfilter/source sdext/source

Stephan Bergmann sbergman at redhat.com
Thu Jul 3 04:12:40 PDT 2014


 hwpfilter/source/hiodev.cxx                |   20 +++++++---------
 hwpfilter/source/hiodev.h                  |    5 ++--
 hwpfilter/source/hstream.cxx               |    5 ----
 hwpfilter/source/hstream.h                 |    5 ----
 hwpfilter/source/hwpfile.cxx               |    4 +--
 hwpfilter/source/hwpfile.h                 |    4 +--
 hwpfilter/source/hwpreader.cxx             |    7 +++--
 sdext/source/pdfimport/test/tests.cxx      |   23 +++++++++----------
 sdext/source/pdfimport/wrapper/wrapper.cxx |   35 ++++++++++++++++++++++++++++-
 9 files changed, 67 insertions(+), 41 deletions(-)

New commits:
commit 4a32ef9c3f3bcb603e253444b4221cebd227b3d8
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Thu Jul 3 11:25:35 2014 +0200

    Improve test code
    
    (never call CPPUNIT_ASSERT etc., which work by throwing exceptions, from a dtor)
    
    Change-Id: I293d54eb40c2ad9205d485ccff0ffd2161257142

diff --git a/sdext/source/pdfimport/test/tests.cxx b/sdext/source/pdfimport/test/tests.cxx
index 8b47c0a..9538c66 100644
--- a/sdext/source/pdfimport/test/tests.cxx
+++ b/sdext/source/pdfimport/test/tests.cxx
@@ -82,7 +82,9 @@ namespace
             m_bImageSeen(false)
         {}
 
-        virtual ~TestSink()
+        virtual ~TestSink() {}
+
+        void check()
         {
             CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "A4 page size (in 100th of points): Width", 79400, m_aPageSize.Width, 0.00000001);
             CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "A4 page size (in 100th of points): Height", 59500, m_aPageSize.Height, 0.0000001 );
@@ -458,16 +460,15 @@ namespace
     public:
         void testXPDFParser()
         {
-            pdfi::ContentSinkSharedPtr pSink( new TestSink() );
-            pdfi::xpdf_ImportFromFile( getURLFromSrc("/sdext/source/pdfimport/test/testinput.pdf"),
-                                       pSink,
-                                       uno::Reference< task::XInteractionHandler >(),
-                                       OUString(),
-                                       getComponentContext() );
-
-            // make destruction explicit, a bunch of things are
-            // checked in the destructor
-            pSink.reset();
+            boost::shared_ptr<TestSink> pSink( new TestSink() );
+            CPPUNIT_ASSERT(
+                pdfi::xpdf_ImportFromFile(
+                    getURLFromSrc("/sdext/source/pdfimport/test/testinput.pdf"),
+                    pSink,
+                    uno::Reference< task::XInteractionHandler >(),
+                    OUString(),
+                    getComponentContext() ) );
+            pSink->check();
         }
 
         void testOdfDrawExport()
commit 44565f46b22c99db4e06353531ba48956efe31be
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Thu Jul 3 11:24:28 2014 +0200

    Check exit code of spawned xpdfimport
    
    Change-Id: I4bea1ebe5c9915ad5e3a4f8fecb516bc056d060d

diff --git a/sdext/source/pdfimport/wrapper/wrapper.cxx b/sdext/source/pdfimport/wrapper/wrapper.cxx
index c60a141..7cdb775 100644
--- a/sdext/source/pdfimport/wrapper/wrapper.cxx
+++ b/sdext/source/pdfimport/wrapper/wrapper.cxx
@@ -1059,7 +1059,7 @@ bool xpdf_ImportFromFile( const OUString&                             rURL,
     oslFileHandle pOut = NULL;
     oslFileHandle pErr = NULL;
     oslSecurity pSecurity = osl_getCurrentSecurity ();
-    const oslProcessError eErr =
+    oslProcessError eErr =
         osl_executeProcess_WithRedirectedIO(converterURL.pData,
                                             args,
                                             nArgs,
@@ -1115,6 +1115,39 @@ bool xpdf_ImportFromFile( const OUString&                             rURL,
         osl_closeFile(pOut);
     if( pErr )
         osl_closeFile(pErr);
+    eErr = osl_joinProcess(aProcess);
+    if (eErr == osl_Process_E_None)
+    {
+        oslProcessInfo info;
+        info.Size = sizeof info;
+        eErr = osl_getProcessInfo(aProcess, osl_Process_EXITCODE, &info);
+        if (eErr == osl_Process_E_None)
+        {
+            if (info.Code != 0)
+            {
+                SAL_WARN(
+                    "sdext.pdfimport",
+                    "getProcessInfo of " << converterURL
+                        << " failed with exit code " << info.Code);
+                bRet = false;
+            }
+        }
+        else
+        {
+            SAL_WARN(
+                "sdext.pdfimport",
+                "getProcessInfo of " << converterURL << " failed with "
+                    << +eErr);
+            bRet = false;
+        }
+    }
+    else
+    {
+        SAL_WARN(
+            "sdext.pdfimport",
+            "joinProcess of " << converterURL << " failed with " << +eErr);
+        bRet = false;
+    }
     osl_freeProcessHandle(aProcess);
     return bRet;
 }
commit e7118d205d474a3cac747238671b6fa34963eec8
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Thu Jul 3 09:17:53 2014 +0200

    HStream::closeInput does nothing
    
    Change-Id: I0d57e227be45bb2c098969ab24eedab30514313f

diff --git a/hwpfilter/source/hiodev.cxx b/hwpfilter/source/hiodev.cxx
index 9e92219..ec25343 100644
--- a/hwpfilter/source/hiodev.cxx
+++ b/hwpfilter/source/hiodev.cxx
@@ -146,9 +146,7 @@ void HStreamIODev::close(void)
 /* 플러시한 후 닫는다. */
     this->flush();
     if (_gzfp)
-        gz_close(_gzfp);                          /* gz_close() calls stream_closeInput() */
-    else
-        _stream->closeInput();
+        gz_close(_gzfp);
     _gzfp = NULL;
 }
 
diff --git a/hwpfilter/source/hstream.cxx b/hwpfilter/source/hstream.cxx
index 5cd9354..e3c1b42 100644
--- a/hwpfilter/source/hstream.cxx
+++ b/hwpfilter/source/hstream.cxx
@@ -66,9 +66,4 @@ int HStream::available() const
     return size - pos;
 }
 
-
-void HStream::closeInput()
-{
-}
-
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/hwpfilter/source/hstream.h b/hwpfilter/source/hstream.h
index 9535ced..426d396 100644
--- a/hwpfilter/source/hstream.h
+++ b/hwpfilter/source/hstream.h
@@ -46,10 +46,7 @@ class HStream
  * @returns Size of remained stream
  */
         int available() const;
-/**
- * remove the stream from this object.
- */
-        void closeInput();
+
     private:
         int size;
         byte *seq;
commit 2617def8d1430e093f6a482a72727b2965a8a8a6
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Thu Jul 3 09:10:17 2014 +0200

    Fix (harmless) stack-use-after-return
    
    ...as reported by -fsanitize=address CppunitTest_hwpfilter_test_hwpfilter, where
    stack-local HStream stream from HwpReader::filter is still referenced from
    HStreamIODev in
    
      HStreamIODev::close
      HStreamIODev::~HStreamIODev
      HWPFile::~HWPFile
      HwpReader::~HwpReader
    
    which is only harmless because HStream::closeInput is a nop.
    
    Change-Id: Idbc5539ab5f463ec6d5d72f428ce60327ebdb063

diff --git a/hwpfilter/source/hiodev.cxx b/hwpfilter/source/hiodev.cxx
index d5f993d..9e92219 100644
--- a/hwpfilter/source/hiodev.cxx
+++ b/hwpfilter/source/hiodev.cxx
@@ -107,7 +107,7 @@ int HIODev::read4b(void *ptr, int nmemb)
 
 
 // hfileiodev class
-HStreamIODev::HStreamIODev(HStream & stream):_stream(stream)
+HStreamIODev::HStreamIODev(HStream * stream):_stream(stream)
 {
     init();
 }
@@ -128,7 +128,7 @@ void HStreamIODev::init()
 
 bool HStreamIODev::open()
 {
-    if (!(_stream.available()))
+    if (!(_stream->available()))
         return false;
     return true;
 }
@@ -148,7 +148,7 @@ void HStreamIODev::close(void)
     if (_gzfp)
         gz_close(_gzfp);                          /* gz_close() calls stream_closeInput() */
     else
-        _stream.closeInput();
+        _stream->closeInput();
     _gzfp = NULL;
 }
 
@@ -164,7 +164,7 @@ bool HStreamIODev::setCompressed(bool flag)
 {
     compressed = flag;
     if (flag == true)
-        return 0 != (_gzfp = gz_open(_stream));
+        return 0 != (_gzfp = gz_open(*_stream));
     else if (_gzfp)
     {
         gz_flush(_gzfp, Z_FINISH);
@@ -181,7 +181,7 @@ bool HStreamIODev::setCompressed(bool flag)
 
 int HStreamIODev::read1b()
 {
-    int res = (compressed) ? GZREAD(rBuf, 1) : _stream.readBytes(rBuf, 1);
+    int res = (compressed) ? GZREAD(rBuf, 1) : _stream->readBytes(rBuf, 1);
 
     if (res <= 0)
         return -1;
@@ -192,7 +192,7 @@ int HStreamIODev::read1b()
 
 int HStreamIODev::read2b()
 {
-    int res = (compressed) ? GZREAD(rBuf, 2) : _stream.readBytes(rBuf, 2);
+    int res = (compressed) ? GZREAD(rBuf, 2) : _stream->readBytes(rBuf, 2);
 
     if (res <= 0)
         return -1;
@@ -203,7 +203,7 @@ int HStreamIODev::read2b()
 
 int HStreamIODev::read4b()
 {
-    int res = (compressed) ? GZREAD(rBuf, 4) : _stream.readBytes(rBuf, 4);
+    int res = (compressed) ? GZREAD(rBuf, 4) : _stream->readBytes(rBuf, 4);
 
     if (res <= 0)
         return -1;
@@ -216,7 +216,7 @@ int HStreamIODev::read4b()
 int HStreamIODev::readBlock(void *ptr, int size)
 {
     int count =
-        (compressed) ? GZREAD(ptr, size) : _stream.readBytes((byte *) ptr,
+        (compressed) ? GZREAD(ptr, size) : _stream->readBytes((byte *) ptr,
 
         size);
 
@@ -242,7 +242,7 @@ int HStreamIODev::skipBlock(int size)
                 return size - remain;
           }
      }
-    return _stream.skipBytes(size);
+    return _stream->skipBytes(size);
 }
 
 
diff --git a/hwpfilter/source/hiodev.h b/hwpfilter/source/hiodev.h
index 40783f5..a47de8f 100644
--- a/hwpfilter/source/hiodev.h
+++ b/hwpfilter/source/hiodev.h
@@ -29,6 +29,7 @@
 
 #include <stdio.h>
 
+#include <boost/scoped_ptr.hpp>
 #include <sal/types.h>
 
 #include "hwplib.h"
@@ -74,10 +75,10 @@ class HStreamIODev : public HIODev
 {
     private:
 /* zlib으로 압축을 풀기 위한 자료 구조 */
+        boost::scoped_ptr<HStream> _stream;
         gz_stream *_gzfp;
-        HStream& _stream;
     public:
-        HStreamIODev(HStream& stream);
+        HStreamIODev(HStream* stream);
         virtual ~HStreamIODev();
 /**
  * Check whether the stream is available
diff --git a/hwpfilter/source/hwpfile.cxx b/hwpfilter/source/hwpfile.cxx
index 5f5b8e3..c4a0bfc 100644
--- a/hwpfilter/source/hwpfile.cxx
+++ b/hwpfilter/source/hwpfile.cxx
@@ -81,7 +81,7 @@ HWPFile::~HWPFile()
     }
 }
 
-int HWPFile::ReadHwpFile(HStream & stream)
+int HWPFile::ReadHwpFile(HStream * stream)
 {
     if (Open(stream) != HWP_NoError)
         return State();
@@ -108,7 +108,7 @@ int detect_hwp_version(const char *str)
 
 // HIODev wrapper
 
-int HWPFile::Open(HStream & stream)
+int HWPFile::Open(HStream * stream)
 {
     HStreamIODev *hstreamio = new HStreamIODev(stream);
 
diff --git a/hwpfilter/source/hwpfile.h b/hwpfilter/source/hwpfile.h
index f812f81..82ba103 100644
--- a/hwpfilter/source/hwpfile.h
+++ b/hwpfilter/source/hwpfile.h
@@ -110,7 +110,7 @@ class DLLEXPORT HWPFile
  * @returns 0 if success, otherwise error code
  * @see State()
  */
-        int Open( HStream & );
+        int Open( HStream * );
 
 /**
  * Say current state
@@ -170,7 +170,7 @@ class DLLEXPORT HWPFile
 /**
  * Reads all information of hwp file from stream
  */
-        int ReadHwpFile( HStream &);
+        int ReadHwpFile( HStream *);
 /**
  * Reads document information of hwp file from HIODev
  */
diff --git a/hwpfilter/source/hwpreader.cxx b/hwpfilter/source/hwpreader.cxx
index f140add..914f6b4 100644
--- a/hwpfilter/source/hwpreader.cxx
+++ b/hwpfilter/source/hwpreader.cxx
@@ -25,6 +25,7 @@
 #include <math.h>
 
 #include <comphelper/newarray.hxx>
+#include <o3tl/heap_ptr.hxx>
 
 #include "fontmap.hxx"
 #include "formula.h"
@@ -130,7 +131,7 @@ sal_Bool HwpReader::filter(const Sequence< PropertyValue >& rDescriptor) throw(R
     Reference< XInputStream > xInputStream(
         aDescriptor[utl::MediaDescriptor::PROP_INPUTSTREAM()], UNO_QUERY_THROW);
 
-    HStream stream;
+    o3tl::heap_ptr<HStream> stream(new HStream);
     Sequence < sal_Int8 > aBuffer;
     sal_Int32 nRead, nBlock = 32768, nTotal = 0;
     while( true )
@@ -138,13 +139,13 @@ sal_Bool HwpReader::filter(const Sequence< PropertyValue >& rDescriptor) throw(R
         nRead = xInputStream->readBytes(aBuffer, nBlock);
         if( nRead == 0 )
             break;
-        stream.addData( (const byte *)aBuffer.getConstArray(), nRead );
+        stream->addData( (const byte *)aBuffer.getConstArray(), nRead );
         nTotal += nRead;
     }
 
     if( nTotal == 0 ) return sal_False;
 
-    if (hwpfile.ReadHwpFile(stream))
+    if (hwpfile.ReadHwpFile(stream.release()))
           return sal_False;
 
     if (m_rxDocumentHandler.is())


More information about the Libreoffice-commits mailing list