[glib] gbookmarkfile: Cleaner error handling code to pacify static analysis



commit f7d7e5ab2f3f9421f9df5d76487f37d4bdc78088
Author: Colin Walters <walters verbum org>
Date:   Thu Jun 12 12:53:18 2014 -0400

    gbookmarkfile: Cleaner error handling code to pacify static analysis
    
    A static analyzer flagged the g_file_get_contents() call as not
    checking its return value.  While the code here is actually correct,
    it's verbose at best.
    
    I think the "goto out + cleanup" code style is substantially cleaner,
    less error prone, and easier to read.  It also will pacify the static
    analyzer.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=731584

 glib/gbookmarkfile.c |   35 +++++++++--------------------------
 1 files changed, 9 insertions(+), 26 deletions(-)
---
diff --git a/glib/gbookmarkfile.c b/glib/gbookmarkfile.c
index 8b8b50a..3123669 100644
--- a/glib/gbookmarkfile.c
+++ b/glib/gbookmarkfile.c
@@ -1673,40 +1673,23 @@ g_bookmark_file_load_from_file (GBookmarkFile  *bookmark,
                                const gchar    *filename,
                                GError        **error)
 {
-  gchar *buffer;
+  gboolean ret = FALSE;
+  gchar *buffer = NULL;
   gsize len;
-  GError *read_error;
-  gboolean retval;
        
   g_return_val_if_fail (bookmark != NULL, FALSE);
   g_return_val_if_fail (filename != NULL, FALSE);
 
-  read_error = NULL;
-  g_file_get_contents (filename, &buffer, &len, &read_error);
-  if (read_error)
-    {
-      g_propagate_error (error, read_error);
-
-      return FALSE;
-    }
+  if (!g_file_get_contents (filename, &buffer, &len, error))
+    goto out;
   
-  read_error = NULL;
-  retval = g_bookmark_file_load_from_data (bookmark,
-                                          buffer,
-                                          len,
-                                          &read_error);
-  if (read_error)
-    {
-      g_propagate_error (error, read_error);
-
-      g_free (buffer);
-
-      return FALSE;
-    }
+  if (!g_bookmark_file_load_from_data (bookmark, buffer, len, error))
+    goto out;
 
+  ret = TRUE;
+ out:
   g_free (buffer);
-
-  return retval;
+  return ret;
 }
 
 


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