[libxml++] Check some libxml function return values.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libxml++] Check some libxml function return values.
- Date: Fri, 26 Nov 2010 14:51:27 +0000 (UTC)
commit f23a72661f395b444f962a7636055f860ba1167c
Author: Murray Cumming <murrayc murrayc com>
Date: Fri Nov 26 15:51:16 2010 +0100
Check some libxml function return values.
* libxml++/document.cc: do_write_to_stream():
* libxml++/schema.cc: set_document(): Check the results from
xmlSchemaNewDocParserCtxt() and xmlSaveFormatFileTo().
Bug #635846 (Markus Elfring).
ChangeLog | 9 +++++++++
libxml++/document.cc | 15 +++++++++++----
libxml++/schema.cc | 22 +++++++++++++++++++---
3 files changed, 39 insertions(+), 7 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 0709564..45f72f8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2010-11-26 Murray Cumming <murrayc murrayc com>
+
+ Check some libxml function return values.
+
+ * libxml++/document.cc: do_write_to_stream():
+ * libxml++/schema.cc: set_document(): Check the results from
+ xmlSchemaNewDocParserCtxt() and xmlSaveFormatFileTo().
+ Bug #635846 (Markus Elfring).
+
2.33.1:
2010-11-14 Murray Cumming <murrayc murrayc com>
diff --git a/libxml++/document.cc b/libxml++/document.cc
index df159fb..6eec443 100644
--- a/libxml++/document.cc
+++ b/libxml++/document.cc
@@ -199,9 +199,7 @@ void Document::do_write_to_file(
{
KeepBlanks k(KeepBlanks::Default);
xmlIndentTreeOutput = format?1:0;
- int result = 0;
-
- result = xmlSaveFormatFileEnc(filename.c_str(), impl_, encoding.empty() ? 0 : encoding.c_str(), format?1:0);
+ const int result = xmlSaveFormatFileEnc(filename.c_str(), impl_, encoding.empty() ? 0 : encoding.c_str(), format?1:0);
if(result == -1)
{
@@ -250,7 +248,16 @@ void Document::do_write_to_stream(std::ostream& output, const Glib::ustring& enc
{
// TODO assert document encoding is UTF-8 if encoding is different than UTF-8
OStreamOutputBuffer buffer(output, encoding);
- xmlSaveFormatFileTo(buffer.cobj(), impl_, encoding.c_str(), format?1:0);
+ const int result = xmlSaveFormatFileTo(buffer.cobj(), impl_, encoding.c_str(), format ? 1 : 0);
+
+ if(result == -1)
+ {
+ #ifdef LIBXMLCPP_EXCEPTIONS_ENABLED
+ throw exception("do_write_to_stream() failed.");
+ #else
+ return;
+ #endif //LIBXMLCPP_EXCEPTIONS_ENABLED
+ }
}
void Document::set_entity_declaration(const Glib::ustring& name, XmlEntityType type,
diff --git a/libxml++/schema.cc b/libxml++/schema.cc
index 12d400b..a589083 100644
--- a/libxml++/schema.cc
+++ b/libxml++/schema.cc
@@ -37,14 +37,30 @@ void Schema::set_document(Document* document, bool embed)
release_underlying();
xmlSchemaParserCtxtPtr context = xmlSchemaNewDocParserCtxt( document->cobj() );
- impl_ = xmlSchemaParse( context );
+
+ if(!context)
+ {
#ifdef LIBXMLCPP_EXCEPTIONS_ENABLED
- if ( !impl_ )
throw parse_error("Schema could not be parsed");
+#else
+ return;
#endif
+ }
+
+ impl_ = xmlSchemaParse(context);
+ if(!impl_)
+ {
+ xmlSchemaFreeParserCtxt(context);
+#ifdef LIBXMLCPP_EXCEPTIONS_ENABLED
+ throw parse_error("Schema could not be parsed");
+#else
+ return;
+#endif
+ }
+
impl_->_private = this;
embedded_doc_ = embed;
- xmlSchemaFreeParserCtxt( context );
+ xmlSchemaFreeParserCtxt(context);
}
Glib::ustring Schema::get_name() const
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]