[dia] Improve robustness of dia_context_get_filename() use
- From: Hans Breuer <hans src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dia] Improve robustness of dia_context_get_filename() use
- Date: Sun, 19 Jan 2014 12:02:45 +0000 (UTC)
commit 72c3148b956a6c352b7c5fbaf6bfac758760f688
Author: Hans Breuer <hans breuer org>
Date: Sun Jan 19 12:23:56 2014 +0100
Improve robustness of dia_context_get_filename() use
Not setting the filename on the context should not produce
crashes. So don't return NULL with dia_context_get_filename()
but a valid string. Should be more reliable than adding
NULL pointer to all the users.
lib/diacontext.c | 12 ++++++++++--
objects/standard/image.c | 2 +-
2 files changed, 11 insertions(+), 3 deletions(-)
---
diff --git a/lib/diacontext.c b/lib/diacontext.c
index 60f1168..04dfcf8 100644
--- a/lib/diacontext.c
+++ b/lib/diacontext.c
@@ -129,12 +129,21 @@ dia_context_set_filename (DiaContext *context,
context->filename = g_strdup (filename);
}
+/*!
+ * \brief Get the filename previously set with dia_context_set_filename()
+ *
+ * Returns the filename previously set with dia_context_set_filename(). For convenience
+ * of the API user a valid string gets returned even if no filename is set.
+ *
+ * @param context explicit this pointer
+ * @return the filename or "?" instead of NULL
+ */
const char *
dia_context_get_filename (DiaContext *context)
{
g_return_val_if_fail (context != NULL, "");
- return context->filename;
+ return context->filename ? context->filename : "?";
}
void
@@ -144,7 +153,6 @@ dia_context_add_message (DiaContext *context,
gchar *msg;
va_list args;
-
g_return_if_fail (context != NULL);
g_return_if_fail (context != NULL);
diff --git a/objects/standard/image.c b/objects/standard/image.c
index 23eefc8..2957464 100644
--- a/objects/standard/image.c
+++ b/objects/standard/image.c
@@ -655,7 +655,7 @@ image_save(Image *image, ObjectNode obj_node, DiaContext *ctx)
if (g_path_is_absolute(image->file)) { /* Absolute pathname */
diafile_dir = get_directory(dia_context_get_filename (ctx));
- if (strncmp(diafile_dir, image->file, strlen(diafile_dir))==0) {
+ if (diafile_dir && strncmp(diafile_dir, image->file, strlen(diafile_dir))==0) {
/* The image pathname has the dia file pathname in the begining */
/* Save the relative path: */
data_add_filename(new_attribute(obj_node, "file"),
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]