Code

Catch failures in fopen of XML files. Fixes #1374551.
authorcth103 <cth103@users.sourceforge.net>
Mon, 23 Jan 2006 14:19:27 +0000 (14:19 +0000)
committercth103 <cth103@users.sourceforge.net>
Mon, 23 Jan 2006 14:19:27 +0000 (14:19 +0000)
ChangeLog
src/xml/repr-io.cpp

index d856ba05b5de8d2c836adda610c1f43a011435bf..18df22f3fd8673595a2979cf31b446dd3da65a84 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,6 +3,9 @@
        * src/selection.cpp: fix a typo in one of my previous commits.
        Closes #1401357.
 
+       * src/xml/repr-io.cpp: catch failures in fopen of XML files.
+       Closes #1374551.
+
 2006-01-20  Michael Wybrow  <mjwybrow@users.sourceforge.net>
 
        * src/widgets/toolbox.cpp, src/widgets/desktop-widget.cpp,
index 02aca4dc6786730a5ccf28169d733acc54097d11..bb62393fc541981002e120d4e03b1db8d14e89e4 100644 (file)
@@ -16,7 +16,7 @@
 # include <config.h>
 #endif
 
-
+#include <stdexcept>
 
 #include "xml/repr.h"
 #include "xml/attribute-record.h"
@@ -80,9 +80,13 @@ private:
     Inkscape::IO::GzipInputStream* gzin;
 };
 
-void XmlSource::setFile( char const * filename ) {
+void XmlSource::setFile(char const *filename)
+{
     this->filename = filename;
     fp = Inkscape::IO::fopen_utf8name(filename, "r");
+    if (fp == NULL) {
+        throw std::runtime_error("Could not open file for reading");
+    }
     first = true;
 }
 
@@ -214,7 +218,14 @@ sp_repr_read_file (const gchar * filename, const gchar *default_ns)
     Inkscape::IO::dump_fopen_call( filename, "N" );
 
     XmlSource src;
-    src.setFile(filename);
+    try
+    {
+        src.setFile(filename);
+    }
+    catch (...)
+    {
+        return NULL;
+    }
 
     xmlDocPtr doubleDoc = xmlReadIO( XmlSource::readCb,
                                      XmlSource::closeCb,