[at-spi2-core] Remove some redundant out-of-memory checks



commit 0af92999fa225c8c3a7dd2d55208e96907fd929d
Author: Mike Gorse <mgorse novell com>
Date:   Thu May 5 17:14:02 2011 -0500

    Remove some redundant out-of-memory checks
    
    If malloc returns NULL, then g_malloc will call g_error and thus abort, so
    it is redundant to check the return value of g_new0 and the like, since glib
    will already have aborted the program rather than returning a NULL value.
    "Cleaning up" the code by removing some of these checks.

 atspi/atspi-accessible.c      |    9 ++-------
 atspi/atspi-component.c       |   18 ++++++------------
 atspi/atspi-device-listener.c |    2 --
 atspi/atspi-event-listener.c  |   38 ++++++++++----------------------------
 atspi/atspi-hyperlink.c       |    5 ++---
 atspi/atspi-misc.c            |    2 --
 atspi/atspi-registry.c        |    2 --
 atspi/atspi-text.c            |   36 +++++++++++++-----------------------
 8 files changed, 33 insertions(+), 79 deletions(-)
---
diff --git a/atspi/atspi-accessible.c b/atspi/atspi-accessible.c
index dfeed59..a12967e 100644
--- a/atspi/atspi-accessible.c
+++ b/atspi/atspi-accessible.c
@@ -523,12 +523,9 @@ atspi_accessible_get_relation_set (AtspiAccessible *obj, GError **error)
   dbus_message_iter_recurse (&iter, &iter_array);
   while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
   {
-    GArray *new_array;
     AtspiRelation *relation;
     relation = _atspi_relation_new_from_iter (&iter_array);
-    new_array = g_array_append_val (ret, relation);
-    if (new_array)
-      ret = new_array;
+    ret = g_array_append_val (ret, relation);
     dbus_message_iter_next (&iter_array);
   }
   dbus_message_unref (reply);
@@ -787,6 +784,7 @@ atspi_accessible_get_toolkit_version (AtspiAccessible *obj, GError **error)
       return NULL;
   return g_strdup (ret);
 }
+
 /**
  * atspi_accessible_get_toolkit_version:
  * @obj: a pointer to the #AtspiAccessible object on which to operate.
@@ -1303,9 +1301,6 @@ atspi_accessible_get_interfaces (AtspiAccessible *obj)
 {
   GArray *ret = g_array_new (TRUE, TRUE, sizeof (gchar *));
 
-  if (!ret)
-    return NULL;
-
   g_return_val_if_fail (obj != NULL, NULL);
 
   append_const_val (ret, "Accessible");
diff --git a/atspi/atspi-component.c b/atspi/atspi-component.c
index a4c3632..bd9ef2b 100644
--- a/atspi/atspi-component.c
+++ b/atspi/atspi-component.c
@@ -39,13 +39,10 @@ AtspiRect *
 atspi_rect_copy (AtspiRect *src)
 {
   AtspiRect *dst = g_new (AtspiRect, 1);
-  if (dst)
-  {
-    dst->x = src->x;
-    dst->y = src->y;
-    dst->height = src->height;
-    dst->width = src->width;
-  }
+  dst->x = src->x;
+  dst->y = src->y;
+  dst->height = src->height;
+  dst->width = src->width;
   return dst;
 }
 
@@ -55,11 +52,8 @@ AtspiPoint *
 atspi_point_copy (AtspiPoint *src)
 {
   AtspiPoint *dst = g_new (AtspiPoint, 1);
-  if (dst)
-  {
-    dst->x = src->x;
-    dst->y = src->y;
-  }
+  dst->x = src->x;
+  dst->y = src->y;
   return dst;
 }
 
diff --git a/atspi/atspi-device-listener.c b/atspi/atspi-device-listener.c
index 669f874..48ecc45 100644
--- a/atspi/atspi-device-listener.c
+++ b/atspi/atspi-device-listener.c
@@ -118,8 +118,6 @@ static AtspiDeviceEvent *
 atspi_device_event_copy (AtspiDeviceEvent *src)
 {
   AtspiDeviceEvent *dst = g_new0 (AtspiDeviceEvent, 1);
-  if (!dst)
-    return NULL;
   dst->type = src->type;
   dst->id = src->id;
   dst->hw_code = src->hw_code;
diff --git a/atspi/atspi-event-listener.c b/atspi/atspi-event-listener.c
index e5a56c7..b81e5b6 100644
--- a/atspi/atspi-event-listener.c
+++ b/atspi/atspi-event-listener.c
@@ -79,8 +79,6 @@ callback_ref (void *callback, GDestroyNotify callback_destroyed)
   if (!info)
   {
     info = g_new (CallbackInfo, 1);
-    if (!info)
-      return;
     info->callback = callback;
     info->callback_destroyed = callback_destroyed;
     info->ref_count = 1;
@@ -332,20 +330,14 @@ convert_event_type_to_dbus (const char *eventType, char **categoryp, char **name
     if (name && name [0])
     {
       gchar *new_str = g_strconcat (*matchrule, ",member='", name, "'", NULL);
-      if (new_str)
-      {
-        g_free (*matchrule);
-        *matchrule = new_str;
-      }
+      g_free (*matchrule);
+      *matchrule = new_str;
     }
     if (detail && detail [0])
     {
       gchar *new_str = g_strconcat (*matchrule, ",arg0='", detail, "'", NULL);
-      if (new_str)
-      {
-        g_free (*matchrule);
-        *matchrule = new_str;
-      }
+      g_free (*matchrule);
+      *matchrule = new_str;
     }
   }
   if (categoryp) *categoryp = category;
@@ -512,7 +504,6 @@ atspi_event_listener_register_from_callback (AtspiEventListenerCB callback,
   }
 
   e = g_new (EventListenerEntry, 1);
-  if (!e) return FALSE;
   e->callback = callback;
   e->user_data = user_data;
   e->callback_destroyed = callback_destroyed;
@@ -806,30 +797,21 @@ atspi_dbus_handle_event (DBusConnection *bus, DBusMessage *message, void *data)
   if (strcasecmp  (category, name) != 0)
   {
     p = g_strconcat (converted_type, ":", name, NULL);
-    if (p)
-    {
-      g_free (converted_type);
-      converted_type = p;
-    }
+    g_free (converted_type);
+    converted_type = p;
   }
   else if (detail [0] == '\0')
   {
     p = g_strconcat (converted_type, ":",  NULL);
-    if (p)
-    {
-      g_free (converted_type);
-      converted_type = p;
-    }
+    g_free (converted_type);
+    converted_type = p;
   }
 
   if (detail[0] != '\0')
   {
     p = g_strconcat (converted_type, ":", detail, NULL);
-    if (p)
-    {
-      g_free (converted_type);
-      converted_type = p;
-    }
+    g_free (converted_type);
+    converted_type = p;
   }
   e.type = converted_type;
   e.source = _atspi_ref_accessible (dbus_message_get_sender(message), dbus_message_get_path(message));
diff --git a/atspi/atspi-hyperlink.c b/atspi/atspi-hyperlink.c
index 57c4b81..c2f3d5b 100644
--- a/atspi/atspi-hyperlink.c
+++ b/atspi/atspi-hyperlink.c
@@ -136,10 +136,9 @@ atspi_hyperlink_get_index_range (AtspiHyperlink *obj, GError **error)
   dbus_int32_t d_start_offset, d_end_offset;
   AtspiRange *ret = g_new (AtspiRange, 1);
 
-  if (ret)
-    ret->start_offset = ret->end_offset = -1;
+  ret->start_offset = ret->end_offset = -1;
 
-  if (!obj || !ret)
+  if (!obj)
     return ret;
 
   _atspi_dbus_call (obj, atspi_interface_hyperlink, "GetIndexRange", error, "=>ii", &d_start_offset, &d_end_offset);
diff --git a/atspi/atspi-misc.c b/atspi/atspi-misc.c
index d0ded39..1f51fa9 100644
--- a/atspi/atspi-misc.c
+++ b/atspi/atspi-misc.c
@@ -718,8 +718,6 @@ defer_message (DBusConnection *connection, DBusMessage *message, void *user_data
   BusDataClosure *closure = g_new (BusDataClosure, 1);
   GList *new_list;
 
-  if (!closure)
-    return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
   closure->bus = dbus_connection_ref (bus);
   closure->message = dbus_message_ref (message);
   closure->data = user_data;
diff --git a/atspi/atspi-registry.c b/atspi/atspi-registry.c
index 2045541..9856be3 100644
--- a/atspi/atspi-registry.c
+++ b/atspi/atspi-registry.c
@@ -361,8 +361,6 @@ atspi_key_definition_copy (AtspiKeyDefinition *src)
   AtspiKeyDefinition *dst;
 
   dst = g_new0 (AtspiKeyDefinition, 1);
-  if (!dst)
-    return NULL;
   dst->keycode = src->keycode;
   dst->keysym = src->keysym;
   if (src->keystring)
diff --git a/atspi/atspi-text.c b/atspi/atspi-text.c
index c5589b3..59f0730 100644
--- a/atspi/atspi-text.c
+++ b/atspi/atspi-text.c
@@ -29,11 +29,8 @@ atspi_range_copy (AtspiRange *src)
 {
   AtspiRange *dst = g_new (AtspiRange, 1);
 
-  if (dst)
-  {
-    dst->start_offset = src->start_offset;
-    dst->end_offset = src->end_offset;
-  }
+  dst->start_offset = src->start_offset;
+  dst->end_offset = src->end_offset;
   return dst;
 }
 
@@ -44,12 +41,9 @@ atspi_text_range_copy (AtspiTextRange *src)
 {
   AtspiTextRange *dst = g_new (AtspiTextRange, 1);
 
-  if (dst)
-  {
-    dst->content = g_strdup (src->content);
-    dst->start_offset = src->start_offset;
-    dst->end_offset = src->end_offset;
-  }
+  dst->content = g_strdup (src->content);
+  dst->start_offset = src->start_offset;
+  dst->end_offset = src->end_offset;
   return dst;
 }
 
@@ -347,9 +341,8 @@ atspi_text_get_text_before_offset (AtspiText *obj,
   dbus_int32_t d_start_offset = -1, d_end_offset = -1;
   AtspiTextRange *range = g_new0 (AtspiTextRange, 1);
 
-  if (range)
-    range->start_offset = range->end_offset = -1;
-  if (!obj || !range)
+  range->start_offset = range->end_offset = -1;
+  if (!obj)
     return range;
 
   _atspi_dbus_call (obj, atspi_interface_text, "GetTextBeforeOffset", error,
@@ -390,9 +383,8 @@ atspi_text_get_text_at_offset (AtspiText *obj,
   dbus_int32_t d_start_offset = -1, d_end_offset = -1;
   AtspiTextRange *range = g_new0 (AtspiTextRange, 1);
 
-  if (range)
-    range->start_offset = range->end_offset = -1;
-  if (!obj || !range)
+  range->start_offset = range->end_offset = -1;
+  if (!obj)
     return range;
 
   _atspi_dbus_call (obj, atspi_interface_text, "GetTextAtOffset", error,
@@ -434,9 +426,8 @@ atspi_text_get_text_after_offset (AtspiText *obj,
   dbus_int32_t d_start_offset = -1, d_end_offset = -1;
   AtspiTextRange *range = g_new0 (AtspiTextRange, 1);
 
-  if (range)
-    range->start_offset = range->end_offset = -1;
-  if (!obj || !range)
+  range->start_offset = range->end_offset = -1;
+  if (!obj)
     return range;
 
   _atspi_dbus_call (obj, atspi_interface_text, "GetTextAfterOffset", error,
@@ -677,10 +668,9 @@ atspi_text_get_selection (AtspiText *obj,
   dbus_int32_t d_start_offset, d_end_offset;
   AtspiRange *ret = g_new (AtspiRange, 1);
 
-  if (ret)
-    ret->start_offset = ret->end_offset = -1;
+  ret->start_offset = ret->end_offset = -1;
 
-  if (!obj || !ret)
+  if (!obj)
     return ret;
 
   _atspi_dbus_call (obj, atspi_interface_text, "GetSelection", error, "i=>ii", d_selection_num, &d_start_offset, &d_end_offset);



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