mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-03 17:56:17 +01:00
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
This commit is contained in:
parent
fcdd25a96e
commit
f7d7e5ab2f
@ -1673,40 +1673,23 @@ g_bookmark_file_load_from_file (GBookmarkFile *bookmark,
|
|||||||
const gchar *filename,
|
const gchar *filename,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
gchar *buffer;
|
gboolean ret = FALSE;
|
||||||
|
gchar *buffer = NULL;
|
||||||
gsize len;
|
gsize len;
|
||||||
GError *read_error;
|
|
||||||
gboolean retval;
|
|
||||||
|
|
||||||
g_return_val_if_fail (bookmark != NULL, FALSE);
|
g_return_val_if_fail (bookmark != NULL, FALSE);
|
||||||
g_return_val_if_fail (filename != NULL, FALSE);
|
g_return_val_if_fail (filename != NULL, FALSE);
|
||||||
|
|
||||||
read_error = NULL;
|
if (!g_file_get_contents (filename, &buffer, &len, error))
|
||||||
g_file_get_contents (filename, &buffer, &len, &read_error);
|
goto out;
|
||||||
if (read_error)
|
|
||||||
{
|
|
||||||
g_propagate_error (error, read_error);
|
|
||||||
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
read_error = NULL;
|
if (!g_bookmark_file_load_from_data (bookmark, buffer, len, error))
|
||||||
retval = g_bookmark_file_load_from_data (bookmark,
|
goto out;
|
||||||
buffer,
|
|
||||||
len,
|
|
||||||
&read_error);
|
|
||||||
if (read_error)
|
|
||||||
{
|
|
||||||
g_propagate_error (error, read_error);
|
|
||||||
|
|
||||||
g_free (buffer);
|
|
||||||
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
ret = TRUE;
|
||||||
|
out:
|
||||||
g_free (buffer);
|
g_free (buffer);
|
||||||
|
return ret;
|
||||||
return retval;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user