[dia] xml: data_filename() handle error case and document it



commit e3b8ff0c2f4d0fce547fdd67d3f48ea89115a126
Author: Hans Breuer <hans breuer org>
Date:   Sat Oct 13 12:28:08 2012 +0200

    xml: data_filename() handle error case and document it

 lib/dia_xml.c |   15 +++++++++++----
 1 files changed, 11 insertions(+), 4 deletions(-)
---
diff --git a/lib/dia_xml.c b/lib/dia_xml.c
index b04cd20..96a81ed 100644
--- a/lib/dia_xml.c
+++ b/lib/dia_xml.c
@@ -945,18 +945,25 @@ data_string(DataNode data, DiaContext *ctx)
  * @param data The data node to read from.
  * @param ctx The context in which this function is called
  * @return The filename value found in the node.  If the node is not a
- *  filename node, an error message is displayed and NULL is returned.
+ *  filename node, an error message is added to ctx and NULL is returned.
  *  The resulting string is in the local filesystem's encoding rather than
  *  UTF-8, and should be freed after use.
- * @bug data_string() can return NULL, what does g_filename_from_utf8 do then?
  * \ingroup DiagramXmlIn
  */
 char *
 data_filename(DataNode data, DiaContext *ctx)
 {
   char *utf8 = data_string(data, ctx);
-  char *filename = g_filename_from_utf8(utf8, -1, NULL, NULL, NULL);
-  g_free(utf8);
+  char *filename = NULL;
+
+  if (utf8) {
+    GError *error = NULL;
+    if ((filename = g_filename_from_utf8(utf8, -1, NULL, NULL, &error)) == NULL) {
+      dia_context_add_message (ctx, "%s", error->message);
+      g_error_free (error);
+    }
+    g_free(utf8);
+  }
   return filename;
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]