mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-03-31 04:43:06 +02:00
gnetworkmonitornetlink: Refactor error handling in read_netlink_messages()
scan-build thinks that it’s possible for `read_netlink_messages()` to return `FALSE` and an unset error (or `TRUE` and a set error), and this belief causes it to emit warnings for code which calls `read_netlink_messages()`. That’s not possible, but the function is written in such a way that following the control flow would be hard for a static analyser. It would have to work out that `retval` and `local_error == NULL` are identical on all control flow branches. Avoid the need for such complex analysis by eliminating `retval` and just using `local_error` throughout. This introduces no functional changes to the code. Signed-off-by: Philip Withnall <pwithnall@gnome.org> Helps: #1767
This commit is contained in:
parent
b3cd9aaa98
commit
ff4c17bc30
@ -310,7 +310,6 @@ read_netlink_messages (GNetworkMonitorNetlink *nl,
|
|||||||
struct sockaddr_nl source_sockaddr;
|
struct sockaddr_nl source_sockaddr;
|
||||||
gsize attrlen;
|
gsize attrlen;
|
||||||
guint8 *dest, *gateway, *oif;
|
guint8 *dest, *gateway, *oif;
|
||||||
gboolean retval = TRUE;
|
|
||||||
|
|
||||||
iv.buffer = NULL;
|
iv.buffer = NULL;
|
||||||
iv.size = 0;
|
iv.size = 0;
|
||||||
@ -319,26 +318,17 @@ read_netlink_messages (GNetworkMonitorNetlink *nl,
|
|||||||
len = g_socket_receive_message (nl->priv->sock, NULL, &iv, 1,
|
len = g_socket_receive_message (nl->priv->sock, NULL, &iv, 1,
|
||||||
NULL, NULL, &flags, NULL, &local_error);
|
NULL, NULL, &flags, NULL, &local_error);
|
||||||
if (len < 0)
|
if (len < 0)
|
||||||
{
|
goto done;
|
||||||
retval = FALSE;
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
|
|
||||||
iv.buffer = g_malloc (len);
|
iv.buffer = g_malloc (len);
|
||||||
iv.size = len;
|
iv.size = len;
|
||||||
len = g_socket_receive_message (nl->priv->sock, &addr, &iv, 1,
|
len = g_socket_receive_message (nl->priv->sock, &addr, &iv, 1,
|
||||||
NULL, NULL, NULL, NULL, &local_error);
|
NULL, NULL, NULL, NULL, &local_error);
|
||||||
if (len < 0)
|
if (len < 0)
|
||||||
{
|
goto done;
|
||||||
retval = FALSE;
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!g_socket_address_to_native (addr, &source_sockaddr, sizeof (source_sockaddr), &local_error))
|
if (!g_socket_address_to_native (addr, &source_sockaddr, sizeof (source_sockaddr), &local_error))
|
||||||
{
|
goto done;
|
||||||
retval = FALSE;
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* If the sender port id is 0 (not fakeable) then the message is from the kernel */
|
/* If the sender port id is 0 (not fakeable) then the message is from the kernel */
|
||||||
if (source_sockaddr.nl_pid != 0)
|
if (source_sockaddr.nl_pid != 0)
|
||||||
@ -353,7 +343,6 @@ read_netlink_messages (GNetworkMonitorNetlink *nl,
|
|||||||
G_IO_ERROR,
|
G_IO_ERROR,
|
||||||
G_IO_ERROR_PARTIAL_INPUT,
|
G_IO_ERROR_PARTIAL_INPUT,
|
||||||
"netlink message was truncated; shouldn't happen...");
|
"netlink message was truncated; shouldn't happen...");
|
||||||
retval = FALSE;
|
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -419,7 +408,6 @@ read_netlink_messages (GNetworkMonitorNetlink *nl,
|
|||||||
"netlink error: %s",
|
"netlink error: %s",
|
||||||
g_strerror (-e->error));
|
g_strerror (-e->error));
|
||||||
}
|
}
|
||||||
retval = FALSE;
|
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -428,7 +416,6 @@ read_netlink_messages (GNetworkMonitorNetlink *nl,
|
|||||||
G_IO_ERROR_INVALID_DATA,
|
G_IO_ERROR_INVALID_DATA,
|
||||||
"unexpected netlink message %d",
|
"unexpected netlink message %d",
|
||||||
msg->nlmsg_type);
|
msg->nlmsg_type);
|
||||||
retval = FALSE;
|
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -437,13 +424,18 @@ read_netlink_messages (GNetworkMonitorNetlink *nl,
|
|||||||
g_free (iv.buffer);
|
g_free (iv.buffer);
|
||||||
g_clear_object (&addr);
|
g_clear_object (&addr);
|
||||||
|
|
||||||
if (!retval && nl->priv->dump_networks)
|
if (local_error != NULL && nl->priv->dump_networks)
|
||||||
finish_dump (nl);
|
finish_dump (nl);
|
||||||
|
|
||||||
if (local_error)
|
if (local_error != NULL)
|
||||||
g_propagate_prefixed_error (error, local_error, "Error on netlink socket: ");
|
{
|
||||||
|
g_propagate_prefixed_error (error, local_error, "Error on netlink socket: ");
|
||||||
return retval;
|
return FALSE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
Loading…
x
Reference in New Issue
Block a user