[glib] Avoid setting unused variables (-Wself-assign)



commit 190f64a0fb0280bcc4a401062abd802db8eb0034
Author: Daniel Macks <dmacks netspace org>
Date:   Thu Mar 19 23:06:28 2015 -0400

    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

 gio/gdbusauth.c              |    9 +++------
 gio/gdbusauthmechanismsha1.c |    1 -
 gio/gdbusmessage.c           |   14 ++++++++------
 gio/gthreadedresolver.c      |    4 +---
 gio/tests/httpd.c            |   15 +++++++++++----
 5 files changed, 23 insertions(+), 20 deletions(-)
---
diff --git a/gio/gdbusauth.c b/gio/gdbusauth.c
index e46e622..1a0ada5 100644
--- a/gio/gdbusauth.c
+++ b/gio/gdbusauth.c
@@ -961,7 +961,6 @@ _g_dbus_auth_run_server (GDBusAuth              *auth,
   GDataInputStream *dis;
   GDataOutputStream *dos;
   GError *local_error;
-  guchar byte;
   gchar *line;
   gsize line_length;
   GDBusAuthMechanism *mech;
@@ -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);
 
-  /* first read the NUL-byte (TODO: read credentials if using a unix domain socket) */
+  /* first read the NUL-byte */
 #ifdef G_OS_UNIX
   if (G_IS_UNIX_CONNECTION (auth->priv->stream))
     {
@@ -1014,8 +1013,7 @@ _g_dbus_auth_run_server (GDBusAuth              *auth,
   else
     {
       local_error = NULL;
-      byte = g_data_input_stream_read_byte (dis, cancellable, &local_error);
-      byte = byte; /* To avoid -Wunused-but-set-variable */
+      (void)g_data_input_stream_read_byte (dis, cancellable, &local_error);
       if (local_error != NULL)
         {
           g_propagate_error (error, local_error);
@@ -1024,8 +1022,7 @@ _g_dbus_auth_run_server (GDBusAuth              *auth,
     }
 #else
   local_error = NULL;
-  byte = g_data_input_stream_read_byte (dis, cancellable, &local_error);
-  byte = byte; /* To avoid -Wunused-but-set-variable */
+  (void)g_data_input_stream_read_byte (dis, cancellable, &local_error);
   if (local_error != NULL)
     {
       g_propagate_error (error, local_error);
diff --git a/gio/gdbusauthmechanismsha1.c b/gio/gdbusauthmechanismsha1.c
index a51430c..88b8f9b 100644
--- a/gio/gdbusauthmechanismsha1.c
+++ b/gio/gdbusauthmechanismsha1.c
@@ -753,7 +753,6 @@ keyring_generate_entry (const gchar  *cookie_context,
               g_strfreev (tokens);
               goto out;
             }
-          line_when = line_when; /* To avoid -Wunused-but-set-variable */
 
 
           /* D-Bus spec says:
diff --git a/gio/gdbusmessage.c b/gio/gdbusmessage.c
index e80794f..7dd458d 100644
--- a/gio/gdbusmessage.c
+++ b/gio/gdbusmessage.c
@@ -1440,7 +1440,9 @@ parse_value_from_blob (GMemoryBuffer       *buf,
 {
   GVariant *ret;
   GError *local_error;
+#ifdef DEBUG_SERIALIZER
   gboolean is_leaf;
+#endif /* DEBUG_SERIALIZER */
   const gchar *type_string;
 
   type_string = g_variant_type_peek_string (type);
@@ -1460,7 +1462,9 @@ parse_value_from_blob (GMemoryBuffer       *buf,
 
   ret = NULL;
 
+#ifdef DEBUG_SERIALIZER
   is_leaf = TRUE;
+#endif /* DEBUG_SERIALIZER */
   local_error = NULL;
   switch (type_string[0])
     {
@@ -1643,8 +1647,8 @@ parse_value_from_blob (GMemoryBuffer       *buf,
 
           array_len = g_memory_buffer_read_uint32 (buf);
 
-          is_leaf = FALSE;
 #ifdef DEBUG_SERIALIZER
+          is_leaf = FALSE;
           g_print (": array spans 0x%04x bytes\n", array_len);
 #endif /* DEBUG_SERIALIZER */
 
@@ -1751,8 +1755,8 @@ parse_value_from_blob (GMemoryBuffer       *buf,
 
           ensure_input_padding (buf, 8);
 
-          is_leaf = FALSE;
 #ifdef DEBUG_SERIALIZER
+          is_leaf = FALSE;
           g_print ("\n");
 #endif /* DEBUG_SERIALIZER */
 
@@ -1786,8 +1790,8 @@ parse_value_from_blob (GMemoryBuffer       *buf,
         {
           ensure_input_padding (buf, 8);
 
-          is_leaf = FALSE;
 #ifdef DEBUG_SERIALIZER
+          is_leaf = FALSE;
           g_print ("\n");
 #endif /* DEBUG_SERIALIZER */
 
@@ -1821,8 +1825,8 @@ parse_value_from_blob (GMemoryBuffer       *buf,
         }
       else if (g_variant_type_is_variant (type))
         {
-          is_leaf = FALSE;
 #ifdef DEBUG_SERIALIZER
+          is_leaf = FALSE;
           g_print ("\n");
 #endif /* DEBUG_SERIALIZER */
 
@@ -1894,8 +1898,6 @@ parse_value_from_blob (GMemoryBuffer       *buf,
           g_free (s);
         }
     }
-#else
-  is_leaf = is_leaf; /* To avoid -Wunused-but-set-variable */
 #endif /* DEBUG_SERIALIZER */
 
   /* sink the reference, if floating */
diff --git a/gio/gthreadedresolver.c b/gio/gthreadedresolver.c
index 7fa266a..7941d95 100644
--- a/gio/gthreadedresolver.c
+++ b/gio/gthreadedresolver.c
@@ -537,7 +537,6 @@ g_resolver_records_from_res_query (const gchar      *rrname,
   gchar namebuf[1024];
   guchar *end, *p;
   guint16 type, qclass, rdlength;
-  guint32 ttl;
   HEADER *header;
   GList *records;
   GVariant *record;
@@ -587,8 +586,7 @@ g_resolver_records_from_res_query (const gchar      *rrname,
       p += dn_expand (answer, end, p, namebuf, sizeof (namebuf));
       GETSHORT (type, p);
       GETSHORT (qclass, p);
-      GETLONG  (ttl, p);
-      ttl = ttl; /* To avoid -Wunused-but-set-variable */
+      p += 4; /* ignore the ttl (type=long) value */
       GETSHORT (rdlength, p);
 
       if (type != rrtype || qclass != C_IN)
diff --git a/gio/tests/httpd.c b/gio/tests/httpd.c
index 41bc6c8..9bca6c9 100644
--- a/gio/tests/httpd.c
+++ b/gio/tests/httpd.c
@@ -67,12 +67,19 @@ handler (GThreadedSocketService *service,
 
   version = NULL;
   tmp = strchr (escaped, ' ');
-  if (tmp != NULL)
+  if (tmp == NULL)
     {
-      *tmp = 0;
-      version = tmp + 1;
+      send_error (out, 400, "Bad Request");
+      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, '?');
   if (query != NULL)


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