Corrected direct use of u_arraylist_t internals.
authorJon A. Cruz <jonc@osg.samsung.com>
Fri, 14 Aug 2015 04:00:04 +0000 (21:00 -0700)
committerErich Keane <erich.keane@intel.com>
Fri, 14 Aug 2015 15:10:43 +0000 (15:10 +0000)
Places in the code were using u_arraylist_t internals, including
sections that were copies of the standard functions. These were
corrected to avoid further divergence and allow for corrections.

Change-Id: I52d251e19d8f80945d71e9d57b5c8107aaa3a4ca
Signed-off-by: Jon A. Cruz <jonc@osg.samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/2205
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Erich Keane <erich.keane@intel.com>
resource/csdk/connectivity/common/inc/uarraylist.h
resource/csdk/connectivity/src/bt_edr_adapter/android/caedrutils.c
resource/csdk/connectivity/src/bt_le_adapter/android/caleclient.c
resource/csdk/connectivity/src/bt_le_adapter/android/caleserver.c
resource/csdk/connectivity/src/camessagehandler.c

index a055a1b..5a64937 100644 (file)
@@ -31,6 +31,10 @@ extern "C"
 
 /**
  * array list structure.
+ *
+ * @note
+ * Members should be treated as private and not accessed directly. Instead
+ * all access should be through the defined u_arraylist_*() functions.
  */
 typedef struct u_arraylist_t
 {
index cbd1fb8..e874a7f 100644 (file)
@@ -571,19 +571,7 @@ CAConnectedState_t CAEDRIsConnectedDevice(const char *remoteAddress)
 
 void CAEDRReorderingDeviceList(uint32_t index)
 {
-    if (index >= g_deviceStateList->length)
-    {
-        return;
-    }
-
-    if (index < g_deviceStateList->length - 1)
-    {
-        memmove(&g_deviceStateList->data[index], &g_deviceStateList->data[index + 1],
-                (g_deviceStateList->length - index - 1) * sizeof(void *));
-    }
-
-    g_deviceStateList->size--;
-    g_deviceStateList->length--;
+    u_arraylist_remove(g_deviceStateList, index);
 }
 
 /**
@@ -942,17 +930,5 @@ uint32_t CAEDRGetSocketListLength()
 
 void CAEDRReorderingDeviceSocketList(uint32_t index)
 {
-    if (index >= g_deviceObjectList->length)
-    {
-        return;
-    }
-
-    if (index < g_deviceObjectList->length - 1)
-    {
-        memmove(&g_deviceObjectList->data[index], &g_deviceObjectList->data[index + 1],
-                (g_deviceObjectList->length - index - 1) * sizeof(void *));
-    }
-
-    g_deviceObjectList->size--;
-    g_deviceObjectList->length--;
+    u_arraylist_remove(g_deviceObjectList, index);
 }
index 38ae49a..54d19fc 100644 (file)
@@ -2875,28 +2875,15 @@ void CALEClientCreateDeviceList()
 
 CAResult_t CALEClientReorderingList(uint32_t index, u_arraylist_t *list)
 {
-    if (!list)
+    if (u_arraylist_remove(list, index) == NULL)
     {
-        OIC_LOG(ERROR, TAG, "list is null");
+        OIC_LOG(ERROR, TAG, "List removal failed.");
         return CA_STATUS_FAILED;
     }
-
-    if (index >= list->length)
-    {
-        OIC_LOG(ERROR, TAG, "index is not available");
-        return CA_STATUS_FAILED;
-    }
-
-    if (index < list->length - 1)
+    else
     {
-        memmove(&list->data[index], &list->data[index + 1],
-                (list->length - index - 1) * sizeof(void *));
+        return CA_STATUS_OK;
     }
-
-    list->size--;
-    list->length--;
-
-    return CA_STATUS_OK;
 }
 
 /**
index db04fac..52df9ec 100644 (file)
@@ -2043,28 +2043,15 @@ CAResult_t CALEServerRemoveDevice(JNIEnv *env, jstring address)
 
 CAResult_t CALEServerReorderinglist(uint32_t index)
 {
-    if (!g_connectedDeviceList)
-    {
-        OIC_LOG(ERROR, TAG, "g_connectedDeviceList is null");
-        return CA_STATUS_FAILED;
-    }
-
-    if (index >= g_connectedDeviceList->length)
+    if (u_arraylist_remove(g_connectedDeviceList, index) == NULL)
     {
-        OIC_LOG(ERROR, TAG, "index is not available");
+        OIC_LOG(ERROR, TAG, "List removal failed.");
         return CA_STATUS_FAILED;
     }
-
-    if (index < g_connectedDeviceList->length - 1)
+    else
     {
-        memmove(&g_connectedDeviceList->data[index], &g_connectedDeviceList->data[index + 1],
-                (g_connectedDeviceList->length - index - 1) * sizeof(void *));
+        return CA_STATUS_OK;
     }
-
-    g_connectedDeviceList->size--;
-    g_connectedDeviceList->length--;
-
-    return CA_STATUS_OK;
 }
 
 JNIEXPORT void JNICALL
index 577479f..84e1e02 100644 (file)
@@ -112,7 +112,7 @@ void CAAddDataToReceiveThread(CAData_t *data)
 static bool CAIsSelectedNetworkAvailable()
 {
     u_arraylist_t *list = CAGetSelectedNetworkList();
-    if (!list || list->length == 0)
+    if (!list || u_arraylist_length(list) == 0)
     {
         OIC_LOG(ERROR, TAG, "No selected network");
         return false;