Fix build warnings. 05/150805/3
authorMichal Bloch <m.bloch@samsung.com>
Mon, 18 Sep 2017 12:05:52 +0000 (14:05 +0200)
committerMichal Bloch <m.bloch@samsung.com>
Mon, 25 Sep 2017 12:06:11 +0000 (14:06 +0200)
Change-Id: I25b3cbbde5f4f8b7016556c2b9c203a743bb6632
Signed-off-by: Michal Bloch <m.bloch@samsung.com>
gio/gkdbus.c
glib/gbytes.c

index 63351d3..66a4985 100755 (executable)
@@ -774,9 +774,9 @@ _g_kdbus_Hello (GKDBusWorker  *worker,
     }
 
   g_debug ("[KDBUS] receive pool size set to %" G_GUINT64_FORMAT "\n", receive_pool_size);
-  worker->receive_pool_size = receive_pool_size; 
+  worker->receive_pool_size = receive_pool_size;
   cmd->pool_size = worker->receive_pool_size;
-  
+
   item = cmd->items;
   item->size = G_STRUCT_OFFSET (struct kdbus_item, str) + conn_name_size + 1;
   item->type = KDBUS_ITEM_CONN_DESCRIPTION;
@@ -822,7 +822,15 @@ _g_kdbus_Hello (GKDBusWorker  *worker,
   memcpy (worker->bus_id, cmd->id128, 16);
 
   worker->unique_id = cmd->id;
-  asprintf (&worker->unique_name, ":1.%llu", (unsigned long long) cmd->id);
+  if (asprintf (&worker->unique_name, ":1.%llu", (unsigned long long) cmd->id) < 0)
+    {
+      g_set_error (error,
+                   G_IO_ERROR,
+                   G_IO_ERROR_UNKNOWN,
+                   "asprintf error: %s",
+                   g_strerror(errno));
+      return NULL;
+    }
 
   /* read bloom filters parameters */
   bloom = NULL;
@@ -1137,7 +1145,16 @@ _g_kdbus_GetListNames (GKDBusWorker  *worker,
         {
           gchar *unique_name;
 
-          asprintf (&unique_name, ":1.%llu", name->id);
+          if (asprintf (&unique_name, ":1.%llu", name->id) < 0)
+            {
+              g_set_error (error,
+                           G_IO_ERROR,
+                           G_IO_ERROR_UNKNOWN,
+                           "asprintf error: %s",
+                           g_strerror(errno));
+              goto error;
+            }
+
           expand_strv (&listnames, unique_name);
           prev_id = name->id;
         }
@@ -1159,6 +1176,10 @@ _g_kdbus_GetListNames (GKDBusWorker  *worker,
   g_kdbus_free_data (worker, cmd.offset);
 
   return listnames;
+
+error:
+  g_strfreev(listnames);
+  return NULL;
 }
 
 
@@ -1385,8 +1406,15 @@ _g_kdbus_GetConnInfo (GKDBusWorker  *worker,
 
   if (flags & G_DBUS_CREDS_UNIQUE_NAME)
     {
-       asprintf (&creds->unique_name, ":1.%llu", (unsigned long long) conn_info->id);
-       //TODO: Error handling
+       if (asprintf (&creds->unique_name, ":1.%llu", (unsigned long long) conn_info->id) < 0)
+         {
+           g_set_error (error,
+                        G_DBUS_ERROR,
+                        G_DBUS_ERROR_FAILED,
+                        "asprintf error: %s",
+                        g_strerror(errno));
+           goto error;
+         }
     }
 
   KDBUS_ITEM_FOREACH(item, conn_info, items)
@@ -1844,15 +1872,37 @@ _g_kdbus_AddMatch (GKDBusWorker  *worker,
             break;
 
           case MATCH_ELEMENT_ARGN:
-            asprintf (&type, "arg%u", element->arg);
-            g_kdbus_bloom_add_pair (worker, bloom, type, element->value);
-            free (type);
+            if (asprintf (&type, "arg%u", element->arg) < 0)
+              {
+                 g_set_error (error,
+                              G_DBUS_ERROR,
+                              G_DBUS_ERROR_FAILED,
+                              "asprintf failed: %s", g_strerror(errno));
+                 match_free (match);
+                 return FALSE;
+              }
+            else
+              {
+                g_kdbus_bloom_add_pair (worker, bloom, type, element->value);
+                free (type);
+              }
             break;
 
           case MATCH_ELEMENT_ARGNPATH:
-            asprintf (&type, "arg%u-slash-prefix", element->arg);
-            g_kdbus_bloom_add_pair (worker, bloom, type, element->value);
-            free (type);
+            if (asprintf (&type, "arg%u-slash-prefix", element->arg) < 0)
+              {
+                 g_set_error (error,
+                              G_DBUS_ERROR,
+                              G_DBUS_ERROR_FAILED,
+                              "asprintf failed: %s", g_strerror(errno));
+                 match_free (match);
+                 return FALSE;
+              }
+            else
+              {
+                g_kdbus_bloom_add_pair (worker, bloom, type, element->value);
+                free (type);
+              }
             break;
 
           case MATCH_ELEMENT_ARG0NAMESPACE:
@@ -2987,7 +3037,7 @@ again:
                 (kmsg->sender_seclabel != NULL))
               {
                 gint check;
-                gchar *destination = g_dbus_message_get_destination (kmsg->message);
+                const gchar *destination = g_dbus_message_get_destination (kmsg->message);
                 if (!destination)
                   destination = worker->unique_name;
 
@@ -3571,71 +3621,80 @@ _g_kdbus_send (GKDBusWorker  *worker,
     {
       int ret = errno;
       gchar *info;
-      asprintf (&info, "sender=%s destination=%s path=%s interface=%s member=%s type=%d",
+      if (asprintf (&info, "sender=%s destination=%s path=%s interface=%s member=%s type=%d",
                        g_dbus_message_get_sender (message),
                        g_dbus_message_get_destination (message),
                        g_dbus_message_get_path (message),
                        g_dbus_message_get_interface (message),
                        g_dbus_message_get_member (message),
-                       g_dbus_message_get_message_type (message));
-
-      errno = ret;
-      if (errno == ENXIO || errno == ESRCH)
-        {
-          if (g_dbus_message_get_flags (message) & G_DBUS_MESSAGE_FLAGS_NO_AUTO_START)
-            g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_NAME_HAS_NO_OWNER,
-                         "Name \"%s\" does not exist, %s", dst_name, info);
-          else
-            g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_SERVICE_UNKNOWN,
-                         "Destination '%s' not known, %s", dst_name, info);
-        }
-      else if (errno == EADDRNOTAVAIL)
-        {
-          g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_SERVICE_UNKNOWN,
-                       "No support for activation for name: %s, %s", dst_name, info);
-        }
-      else if (errno == EXFULL)
-        {
-          g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_LIMITS_EXCEEDED,
-                       "The memory pool of the receiver is full, %s", info);
-        }
-      else if (errno == ENOBUFS)
+                       g_dbus_message_get_message_type (message)) < 0)
         {
-          g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_LIMITS_EXCEEDED,
-                       "Too many pending messages on the receiver side, %s", info);
-        }
-      else if (errno == EMSGSIZE)
-        {
-          g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_LIMITS_EXCEEDED,
-                       "The size of the message is excessive, %s", info);
-        }
-      else if (errno == EMLINK)
-        {
-          g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_LIMITS_EXCEEDED,
-                       "The maximum number of pending replies per connection has been reached, %s", info);
-        }
-      else if (errno == ECANCELED)
-        {
-          g_set_error (error, G_IO_ERROR, G_IO_ERROR_CANCELLED,
-                       "Operation was cancelled, %s", info);
-        }
-      else if (errno == ETIMEDOUT)
-        {
-          g_set_error (error, G_IO_ERROR, G_IO_ERROR_TIMED_OUT,
-                       "Timeout was reached, %s", info);
-        }
-      else if (errno == EPERM)
-        {
-          g_set_error (error, G_IO_ERROR, G_IO_ERROR_PERMISSION_DENIED,
-                       "Permission denied, %s", info);
+        g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "%s", g_strerror(errno));
+        /* If asprintf fails, we lose the ioctl errno,
+         * but without info, we can't give a useful error message.
+         * In practice though, asprintf failure is exceedingly rare.
+         */
         }
       else
         {
-          g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "%s, %s", g_strerror(errno), info);
-          g_warning ("kdbus: %s, %s", g_strerror(errno), info);
+          errno = ret;
+          if (errno == ENXIO || errno == ESRCH)
+            {
+              if (g_dbus_message_get_flags (message) & G_DBUS_MESSAGE_FLAGS_NO_AUTO_START)
+                g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_NAME_HAS_NO_OWNER,
+                             "Name \"%s\" does not exist, %s", dst_name, info);
+              else
+                g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_SERVICE_UNKNOWN,
+                             "Destination '%s' not known, %s", dst_name, info);
+            }
+          else if (errno == EADDRNOTAVAIL)
+            {
+              g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_SERVICE_UNKNOWN,
+                           "No support for activation for name: %s, %s", dst_name, info);
+            }
+          else if (errno == EXFULL)
+            {
+              g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_LIMITS_EXCEEDED,
+                           "The memory pool of the receiver is full, %s", info);
+            }
+          else if (errno == ENOBUFS)
+            {
+              g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_LIMITS_EXCEEDED,
+                           "Too many pending messages on the receiver side, %s", info);
+            }
+            else if (errno == EMSGSIZE)
+            {
+              g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_LIMITS_EXCEEDED,
+                           "The size of the message is excessive, %s", info);
+            }
+          else if (errno == EMLINK)
+            {
+              g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_LIMITS_EXCEEDED,
+                           "The maximum number of pending replies per connection has been reached, %s", info);
+            }
+          else if (errno == ECANCELED)
+            {
+              g_set_error (error, G_IO_ERROR, G_IO_ERROR_CANCELLED,
+                           "Operation was cancelled, %s", info);
+            }
+          else if (errno == ETIMEDOUT)
+            {
+              g_set_error (error, G_IO_ERROR, G_IO_ERROR_TIMED_OUT,
+                           "Timeout was reached, %s", info);
+            }
+          else if (errno == EPERM)
+            {
+              g_set_error (error, G_IO_ERROR, G_IO_ERROR_PERMISSION_DENIED,
+                           "Permission denied, %s", info);
+            }
+          else
+            {
+              g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "%s, %s", g_strerror(errno), info);
+              g_warning ("kdbus: %s, %s", g_strerror(errno), info);
+            }
+          free(info);
         }
       result = FALSE;
-      free(info);
     }
   else if (out_reply != NULL)
     {
index 11f5159..2cdf0e5 100644 (file)
@@ -191,7 +191,7 @@ g_bytes_new (gconstpointer data,
 GBytes *
 g_bytes_new_take_zero_copy_fd (gint fd)
 {
-  GBytesData *bytes;
+  GBytes *bytes;
   struct stat buf;
 
   /* We already checked this is a memfd... */
@@ -204,7 +204,7 @@ g_bytes_new_take_zero_copy_fd (gint fd)
       g_assert_se (close (fd) == 0);
     }
 
-  return (GBytes *) bytes;
+  return bytes;
 }
 
 GBytes *