From ebc759131c475a14bfd60c75a77b7f9a2c50ef5c Mon Sep 17 00:00:00 2001 From: Alberto Mardegan Date: Sun, 17 Apr 2011 11:18:10 +0300 Subject: [PATCH] Better usage of g_set_error* Use g_set_error instead of g_error_new; do not check if the error pointer is non-NULL, because g_set_error() does that internally. Also, use g_set_error_literal() whenever possible. --- libgssdp/gssdp-client.c | 4 +--- libgssdp/gssdp-socket-source.c | 20 +++++++++----------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/libgssdp/gssdp-client.c b/libgssdp/gssdp-client.c index 02851c8..30c45f4 100644 --- a/libgssdp/gssdp-client.c +++ b/libgssdp/gssdp-client.c @@ -1249,15 +1249,13 @@ init_network_info (GSSDPClient *client) &client->priv->network); if (client->priv->iface == NULL) { - if (client->priv->error) - g_set_error (client->priv->error, + g_set_error_literal (client->priv->error, GSSDP_ERROR, GSSDP_ERROR_FAILED, "No default route?"); ret = FALSE; } else if (client->priv->host_ip == NULL) { - if (client->priv->error) g_set_error (client->priv->error, GSSDP_ERROR, GSSDP_ERROR_NO_IP_ADDRESS, diff --git a/libgssdp/gssdp-socket-source.c b/libgssdp/gssdp-socket-source.c index 4c28a8e..182d2d6 100644 --- a/libgssdp/gssdp-socket-source.c +++ b/libgssdp/gssdp-socket-source.c @@ -154,12 +154,11 @@ gssdp_socket_source_do_init (GInitable *initable, self = GSSDP_SOCKET_SOURCE (initable); iface_address = g_inet_address_new_from_string (self->priv->host_ip); if (iface_address == NULL) { - if (error != NULL) { - *error = g_error_new (GSSDP_ERROR, - GSSDP_ERROR_FAILED, - "Invalid host ip: %s", - self->priv->host_ip); - } + g_set_error (error, + GSSDP_ERROR, + GSSDP_ERROR_FAILED, + "Invalid host ip: %s", + self->priv->host_ip); goto error; } @@ -169,11 +168,10 @@ gssdp_socket_source_do_init (GInitable *initable, if (family == G_SOCKET_FAMILY_IPV4) group = g_inet_address_new_from_string (SSDP_ADDR); else { - if (error != NULL) { - *error = g_error_new_literal (GSSDP_ERROR, - GSSDP_ERROR_FAILED, - "IPv6 address"); - } + g_set_error_literal (error, + GSSDP_ERROR, + GSSDP_ERROR_FAILED, + "IPv6 address"); goto error; } -- 2.7.4