[Libreoffice-commits] libcdr.git: 2 commits - src/lib

David Tardon dtardon at redhat.com
Fri May 3 22:17:37 PDT 2013


 src/lib/CDRDocument.cpp  |  167 ++++++++++++++++++++++++-----------------------
 src/lib/libcdr_utils.cpp |    1 
 2 files changed, 88 insertions(+), 80 deletions(-)

New commits:
commit 923e2667b275441ee1861e27c882493c8ebbef4e
Author: David Tardon <dtardon at redhat.com>
Date:   Fri May 3 17:51:16 2013 +0200

    coverity: try harder at not throwing execptions

diff --git a/src/lib/CDRDocument.cpp b/src/lib/CDRDocument.cpp
index 497e27c..952bf5b 100644
--- a/src/lib/CDRDocument.cpp
+++ b/src/lib/CDRDocument.cpp
@@ -133,108 +133,115 @@ bool libcdr::CDRDocument::parse(::WPXInputStream *input, libwpg::WPGPaintInterfa
   try
   {
     version = getCDRVersion(input);
-  }
-  catch (libcdr::EndOfStreamException const &)
-  {
-    // This can only happen if isSupported() has not been called before
-    return false;
-  }
-
-  if (version)
-  {
-    input->seek(0, WPX_SEEK_SET);
-    CDRParserState ps;
-    CDRStylesCollector stylesCollector(ps);
-    CDRParser stylesParser(std::vector<WPXInputStream *>(), &stylesCollector);
-    if (version >= 300)
-      retVal = stylesParser.parseRecords(input);
-    else
-      retVal = stylesParser.parseWaldo(input);
-    if (ps.m_pages.empty())
-      retVal = false;
-    if (retVal)
+    if (version)
     {
       input->seek(0, WPX_SEEK_SET);
-      CDRContentCollector contentCollector(ps, painter);
-      CDRParser contentParser(std::vector<WPXInputStream *>(), &contentCollector);
+      CDRParserState ps;
+      CDRStylesCollector stylesCollector(ps);
+      CDRParser stylesParser(std::vector<WPXInputStream *>(), &stylesCollector);
       if (version >= 300)
-        retVal = contentParser.parseRecords(input);
+        retVal = stylesParser.parseRecords(input);
       else
-        retVal = contentParser.parseWaldo(input);
+        retVal = stylesParser.parseWaldo(input);
+      if (ps.m_pages.empty())
+        retVal = false;
+      if (retVal)
+      {
+        input->seek(0, WPX_SEEK_SET);
+        CDRContentCollector contentCollector(ps, painter);
+        CDRParser contentParser(std::vector<WPXInputStream *>(), &contentCollector);
+        if (version >= 300)
+          retVal = contentParser.parseRecords(input);
+        else
+          retVal = contentParser.parseWaldo(input);
+      }
+      return retVal;
     }
-    return retVal;
+  }
+  catch (libcdr::EndOfStreamException const &)
+  {
+    // This can only happen if isSupported() has not been called before
+    return false;
   }
 
   WPXInputStream *tmpInput = input;
-  CDRZipStream zinput(input);
-  bool isZipDocument = zinput.isOLEStream();
-  std::vector<std::string> dataFiles;
-  if (isZipDocument)
+  std::vector<WPXInputStream *> dataStreams;
+  try
   {
-    input = zinput.getDocumentOLEStream("content/riffData.cdr");
-    if (!input)
+    CDRZipStream zinput(input);
+    bool isZipDocument = zinput.isOLEStream();
+    std::vector<std::string> dataFiles;
+    if (isZipDocument)
     {
-      input = zinput.getDocumentOLEStream("content/root.dat");
-      if (input)
+      input = zinput.getDocumentOLEStream("content/riffData.cdr");
+      if (!input)
       {
-        WPXInputStream *tmpStream = zinput.getDocumentOLEStream("content/dataFileList.dat");
-        if (tmpStream)
+        input = zinput.getDocumentOLEStream("content/root.dat");
+        if (input)
         {
-          std::string dataFileName;
-          while (!tmpStream->atEOS())
+          WPXInputStream *tmpStream = zinput.getDocumentOLEStream("content/dataFileList.dat");
+          if (tmpStream)
           {
-            unsigned char character = readU8(tmpStream);
-            if (character == 0x0a)
+            std::string dataFileName;
+            while (!tmpStream->atEOS())
             {
-              dataFiles.push_back(dataFileName);
-              dataFileName.clear();
+              unsigned char character = readU8(tmpStream);
+              if (character == 0x0a)
+              {
+                dataFiles.push_back(dataFileName);
+                dataFileName.clear();
+              }
+              else
+                dataFileName += (char)character;
             }
-            else
-              dataFileName += (char)character;
+            if (!dataFileName.empty())
+              dataFiles.push_back(dataFileName);
           }
-          if (!dataFileName.empty())
-            dataFiles.push_back(dataFileName);
         }
       }
     }
+    dataStreams.reserve(dataFiles.size());
+    for (unsigned i=0; i<dataFiles.size(); i++)
+    {
+      std::string streamName("content/data/");
+      streamName += dataFiles[i];
+      CDR_DEBUG_MSG(("Extracting stream: %s\n", streamName.c_str()));
+      dataStreams.push_back(zinput.getDocumentOLEStream(streamName.c_str()));
+    }
+    if (!input)
+      input = tmpInput;
+    input->seek(0, WPX_SEEK_SET);
+    CDRParserState ps;
+    // libcdr extension to the getDocumentOLEStream. Will extract the first stream in the
+    // given directory
+    WPXInputStream *cmykProfile = zinput.getDocumentOLEStream("color/profiles/cmyk/");
+    if (cmykProfile)
+    {
+      ps.setColorTransform(cmykProfile);
+      delete cmykProfile;
+    }
+    WPXInputStream *rgbProfile = zinput.getDocumentOLEStream("color/profiles/rgb/");
+    if (rgbProfile)
+    {
+      ps.setColorTransform(rgbProfile);
+      delete rgbProfile;
+    }
+    CDRStylesCollector stylesCollector(ps);
+    CDRParser stylesParser(dataStreams, &stylesCollector);
+    retVal = stylesParser.parseRecords(input);
+    if (ps.m_pages.empty())
+      retVal = false;
+    if (retVal)
+    {
+      input->seek(0, WPX_SEEK_SET);
+      CDRContentCollector contentCollector(ps, painter);
+      CDRParser contentParser(dataStreams, &contentCollector);
+      retVal = contentParser.parseRecords(input);
+    }
   }
-  std::vector<WPXInputStream *> dataStreams(dataFiles.size());
-  for (unsigned i=0; i<dataFiles.size(); i++)
-  {
-    std::string streamName("content/data/");
-    streamName += dataFiles[i];
-    CDR_DEBUG_MSG(("Extracting stream: %s\n", streamName.c_str()));
-    dataStreams[i] = zinput.getDocumentOLEStream(streamName.c_str());
-  }
-  if (!input)
-    input = tmpInput;
-  input->seek(0, WPX_SEEK_SET);
-  CDRParserState ps;
-  // libcdr extension to the getDocumentOLEStream. Will extract the first stream in the
-  // given directory
-  WPXInputStream *cmykProfile = zinput.getDocumentOLEStream("color/profiles/cmyk/");
-  if (cmykProfile)
-  {
-    ps.setColorTransform(cmykProfile);
-    delete cmykProfile;
-  }
-  WPXInputStream *rgbProfile = zinput.getDocumentOLEStream("color/profiles/rgb/");
-  if (rgbProfile)
+  catch (libcdr::EndOfStreamException const &)
   {
-    ps.setColorTransform(rgbProfile);
-    delete rgbProfile;
-  }
-  CDRStylesCollector stylesCollector(ps);
-  CDRParser stylesParser(dataStreams, &stylesCollector);
-  retVal = stylesParser.parseRecords(input);
-  if (ps.m_pages.empty())
     retVal = false;
-  if (retVal)
-  {
-    input->seek(0, WPX_SEEK_SET);
-    CDRContentCollector contentCollector(ps, painter);
-    CDRParser contentParser(dataStreams, &contentCollector);
-    retVal = contentParser.parseRecords(input);
   }
   if (input != tmpInput)
     delete input;
commit e508b60b9bf73ed6bdbc204f33e9f7b5c487fb99
Author: David Tardon <dtardon at redhat.com>
Date:   Fri May 3 17:40:14 2013 +0200

    coverity: add missing break

diff --git a/src/lib/libcdr_utils.cpp b/src/lib/libcdr_utils.cpp
index 00f9193..74d6ed4 100644
--- a/src/lib/libcdr_utils.cpp
+++ b/src/lib/libcdr_utils.cpp
@@ -377,6 +377,7 @@ void libcdr::appendCharacters(WPXString &text, std::vector<unsigned char> charac
       break;
     case 0x88: // CHINESEBIG5
       conv = ucnv_open("windows-950", &status);
+      break;
     case 0xa1: // GREEEK
       conv = ucnv_open("windows-1253", &status);
       break;


More information about the Libreoffice-commits mailing list