Commit 190f64a0 authored by Daniel Macks's avatar Daniel Macks Committed by Philip Withnall

Avoid setting unused variables (-Wself-assign)

Setting a variable and then assigning it to itself avoids
-Wunused-but-set-variable but this specific trick is now caught by
-Wself-assign. Instead, actually use the value or don't bother
assigning it at all:

gdbusauth.c: call g_data_input_stream_read_byte() in void context
gdbusauthmechanismsha1.c: value is actually used
gdbusmessage.c: use consistent preprocessor-token protection
gthreadedresolver.c: skip over bytes in data blob
httpd.c: do something useful with the value

https://bugzilla.gnome.org/show_bug.cgi?id=745723
parent 5d9ccf16
...@@ -961,7 +961,6 @@ _g_dbus_auth_run_server (GDBusAuth *auth, ...@@ -961,7 +961,6 @@ _g_dbus_auth_run_server (GDBusAuth *auth,
GDataInputStream *dis; GDataInputStream *dis;
GDataOutputStream *dos; GDataOutputStream *dos;
GError *local_error; GError *local_error;
guchar byte;
gchar *line; gchar *line;
gsize line_length; gsize line_length;
GDBusAuthMechanism *mech; GDBusAuthMechanism *mech;
...@@ -997,7 +996,7 @@ _g_dbus_auth_run_server (GDBusAuth *auth, ...@@ -997,7 +996,7 @@ _g_dbus_auth_run_server (GDBusAuth *auth,
g_data_input_stream_set_newline_type (dis, G_DATA_STREAM_NEWLINE_TYPE_CR_LF); g_data_input_stream_set_newline_type (dis, G_DATA_STREAM_NEWLINE_TYPE_CR_LF);
/* first read the NUL-byte (TODO: read credentials if using a unix domain socket) */ /* first read the NUL-byte */
#ifdef G_OS_UNIX #ifdef G_OS_UNIX
if (G_IS_UNIX_CONNECTION (auth->priv->stream)) if (G_IS_UNIX_CONNECTION (auth->priv->stream))
{ {
...@@ -1014,8 +1013,7 @@ _g_dbus_auth_run_server (GDBusAuth *auth, ...@@ -1014,8 +1013,7 @@ _g_dbus_auth_run_server (GDBusAuth *auth,
else else
{ {
local_error = NULL; local_error = NULL;
byte = g_data_input_stream_read_byte (dis, cancellable, &local_error); (void)g_data_input_stream_read_byte (dis, cancellable, &local_error);
byte = byte; /* To avoid -Wunused-but-set-variable */
if (local_error != NULL) if (local_error != NULL)
{ {
g_propagate_error (error, local_error); g_propagate_error (error, local_error);
...@@ -1024,8 +1022,7 @@ _g_dbus_auth_run_server (GDBusAuth *auth, ...@@ -1024,8 +1022,7 @@ _g_dbus_auth_run_server (GDBusAuth *auth,
} }
#else #else
local_error = NULL; local_error = NULL;
byte = g_data_input_stream_read_byte (dis, cancellable, &local_error); (void)g_data_input_stream_read_byte (dis, cancellable, &local_error);
byte = byte; /* To avoid -Wunused-but-set-variable */
if (local_error != NULL) if (local_error != NULL)
{ {
g_propagate_error (error, local_error); g_propagate_error (error, local_error);
......
...@@ -753,7 +753,6 @@ keyring_generate_entry (const gchar *cookie_context, ...@@ -753,7 +753,6 @@ keyring_generate_entry (const gchar *cookie_context,
g_strfreev (tokens); g_strfreev (tokens);
goto out; goto out;
} }
line_when = line_when; /* To avoid -Wunused-but-set-variable */
/* D-Bus spec says: /* D-Bus spec says:
......
...@@ -1440,7 +1440,9 @@ parse_value_from_blob (GMemoryBuffer *buf, ...@@ -1440,7 +1440,9 @@ parse_value_from_blob (GMemoryBuffer *buf,
{ {
GVariant *ret; GVariant *ret;
GError *local_error; GError *local_error;
#ifdef DEBUG_SERIALIZER
gboolean is_leaf; gboolean is_leaf;
#endif /* DEBUG_SERIALIZER */
const gchar *type_string; const gchar *type_string;
type_string = g_variant_type_peek_string (type); type_string = g_variant_type_peek_string (type);
...@@ -1460,7 +1462,9 @@ parse_value_from_blob (GMemoryBuffer *buf, ...@@ -1460,7 +1462,9 @@ parse_value_from_blob (GMemoryBuffer *buf,
ret = NULL; ret = NULL;
#ifdef DEBUG_SERIALIZER
is_leaf = TRUE; is_leaf = TRUE;
#endif /* DEBUG_SERIALIZER */
local_error = NULL; local_error = NULL;
switch (type_string[0]) switch (type_string[0])
{ {
...@@ -1643,8 +1647,8 @@ parse_value_from_blob (GMemoryBuffer *buf, ...@@ -1643,8 +1647,8 @@ parse_value_from_blob (GMemoryBuffer *buf,
array_len = g_memory_buffer_read_uint32 (buf); array_len = g_memory_buffer_read_uint32 (buf);
is_leaf = FALSE;
#ifdef DEBUG_SERIALIZER #ifdef DEBUG_SERIALIZER
is_leaf = FALSE;
g_print (": array spans 0x%04x bytes\n", array_len); g_print (": array spans 0x%04x bytes\n", array_len);
#endif /* DEBUG_SERIALIZER */ #endif /* DEBUG_SERIALIZER */
...@@ -1751,8 +1755,8 @@ parse_value_from_blob (GMemoryBuffer *buf, ...@@ -1751,8 +1755,8 @@ parse_value_from_blob (GMemoryBuffer *buf,
ensure_input_padding (buf, 8); ensure_input_padding (buf, 8);
is_leaf = FALSE;
#ifdef DEBUG_SERIALIZER #ifdef DEBUG_SERIALIZER
is_leaf = FALSE;
g_print ("\n"); g_print ("\n");
#endif /* DEBUG_SERIALIZER */ #endif /* DEBUG_SERIALIZER */
...@@ -1786,8 +1790,8 @@ parse_value_from_blob (GMemoryBuffer *buf, ...@@ -1786,8 +1790,8 @@ parse_value_from_blob (GMemoryBuffer *buf,
{ {
ensure_input_padding (buf, 8); ensure_input_padding (buf, 8);
is_leaf = FALSE;
#ifdef DEBUG_SERIALIZER #ifdef DEBUG_SERIALIZER
is_leaf = FALSE;
g_print ("\n"); g_print ("\n");
#endif /* DEBUG_SERIALIZER */ #endif /* DEBUG_SERIALIZER */
...@@ -1821,8 +1825,8 @@ parse_value_from_blob (GMemoryBuffer *buf, ...@@ -1821,8 +1825,8 @@ parse_value_from_blob (GMemoryBuffer *buf,
} }
else if (g_variant_type_is_variant (type)) else if (g_variant_type_is_variant (type))
{ {
is_leaf = FALSE;
#ifdef DEBUG_SERIALIZER #ifdef DEBUG_SERIALIZER
is_leaf = FALSE;
g_print ("\n"); g_print ("\n");
#endif /* DEBUG_SERIALIZER */ #endif /* DEBUG_SERIALIZER */
...@@ -1894,8 +1898,6 @@ parse_value_from_blob (GMemoryBuffer *buf, ...@@ -1894,8 +1898,6 @@ parse_value_from_blob (GMemoryBuffer *buf,
g_free (s); g_free (s);
} }
} }
#else
is_leaf = is_leaf; /* To avoid -Wunused-but-set-variable */
#endif /* DEBUG_SERIALIZER */ #endif /* DEBUG_SERIALIZER */
/* sink the reference, if floating */ /* sink the reference, if floating */
......
...@@ -537,7 +537,6 @@ g_resolver_records_from_res_query (const gchar *rrname, ...@@ -537,7 +537,6 @@ g_resolver_records_from_res_query (const gchar *rrname,
gchar namebuf[1024]; gchar namebuf[1024];
guchar *end, *p; guchar *end, *p;
guint16 type, qclass, rdlength; guint16 type, qclass, rdlength;
guint32 ttl;
HEADER *header; HEADER *header;
GList *records; GList *records;
GVariant *record; GVariant *record;
...@@ -587,8 +586,7 @@ g_resolver_records_from_res_query (const gchar *rrname, ...@@ -587,8 +586,7 @@ g_resolver_records_from_res_query (const gchar *rrname,
p += dn_expand (answer, end, p, namebuf, sizeof (namebuf)); p += dn_expand (answer, end, p, namebuf, sizeof (namebuf));
GETSHORT (type, p); GETSHORT (type, p);
GETSHORT (qclass, p); GETSHORT (qclass, p);
GETLONG (ttl, p); p += 4; /* ignore the ttl (type=long) value */
ttl = ttl; /* To avoid -Wunused-but-set-variable */
GETSHORT (rdlength, p); GETSHORT (rdlength, p);
if (type != rrtype || qclass != C_IN) if (type != rrtype || qclass != C_IN)
......
...@@ -67,12 +67,19 @@ handler (GThreadedSocketService *service, ...@@ -67,12 +67,19 @@ handler (GThreadedSocketService *service,
version = NULL; version = NULL;
tmp = strchr (escaped, ' '); tmp = strchr (escaped, ' ');
if (tmp != NULL) if (tmp == NULL)
{ {
*tmp = 0; send_error (out, 400, "Bad Request");
version = tmp + 1; goto out;
}
*tmp = 0;
version = tmp + 1;
if (!g_str_has_prefix (version, "HTTP/1."))
{
send_error(out, 505, "HTTP Version Not Supported");
goto out;
} }
version = version; /* To avoid -Wunused-but-set-variable */
query = strchr (escaped, '?'); query = strchr (escaped, '?');
if (query != NULL) if (query != NULL)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment