removed unreachable code in resource layer
authorjihwan.seo <jihwan.seo@samsung.com>
Tue, 13 Dec 2016 02:21:06 +0000 (11:21 +0900)
committerAshok Babu Channa <ashok.channa@samsung.com>
Thu, 22 Dec 2016 13:06:00 +0000 (13:06 +0000)
Change-Id: I19367f5f28e32a97f17aa6f7e02423349adeb7ad
Signed-off-by: jihwan.seo <jihwan.seo@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/15531
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Jaehong Jo <jaehong.jo@samsung.com>
Reviewed-by: Dan Mihai <Daniel.Mihai@microsoft.com>
Reviewed-by: Ashok Babu Channa <ashok.channa@samsung.com>
resource/csdk/connectivity/src/bt_le_adapter/android/caleclient.c
resource/csdk/connectivity/src/bt_le_adapter/android/caleutils.c
resource/csdk/connectivity/util/src/camanager/bt_le_manager/android/camanagerleutil.c
resource/csdk/security/provisioning/src/pmutility.c
resource/csdk/security/src/directpairing.c
resource/csdk/stack/src/ocpayload.c
resource/include/WrapperFactory.h
resource/src/OCRepresentation.cpp
resource/unittests/OCPlatformTest.cpp

index e8e7340..daf5909 100644 (file)
@@ -3889,20 +3889,16 @@ bool CALEClientIsValidState(const char* remoteAddress, uint16_t state_type,
         default:
             break;
     }
+    oc_mutex_unlock(g_deviceStateListMutex);
 
     if (target_state == curValue)
     {
-        oc_mutex_unlock(g_deviceStateListMutex);
         return true;
     }
     else
     {
-        oc_mutex_unlock(g_deviceStateListMutex);
         return false;
     }
-
-    oc_mutex_unlock(g_deviceStateListMutex);
-    return false;
 }
 
 void CALEClientCreateDeviceList()
@@ -4466,12 +4462,6 @@ Java_org_iotivity_ca_CaLeClientInterface_caLeGattConnectionStateChangeCallback(J
             CALEClientUpdateSendCnt(env);
             return;
         }
-
-        if (g_sendBuffer)
-        {
-            (*env)->DeleteGlobalRef(env, g_sendBuffer);
-            g_sendBuffer = NULL;
-        }
     }
     return;
 
index 9e7c14d..c72abd8 100644 (file)
@@ -134,8 +134,6 @@ bool CALEIsBondedDevice(JNIEnv *env, jobject bluetoothDevice)
         OIC_LOG(DEBUG, TAG, "remote device is not bonded");
         return false;
     }
-
-    return false;
 }
 
 jobjectArray CALEGetBondedDevices(JNIEnv *env)
index 04121eb..eaec1d1 100644 (file)
@@ -154,7 +154,7 @@ bool CAManagerIsDeviceBonded(JNIEnv *env, jobject btDevice)
     if (!id_bonded)
     {
         OIC_LOG(ERROR, TAG, "id_bonded is null");
-        return false;;
+        return false;
     }
 
     jint jni_bonded_const = (*env)->GetStaticIntField(env, jni_cid_BTDevice, id_bonded);
index f5ed509..6d11043 100644 (file)
@@ -466,7 +466,6 @@ bool PMGenerateQuery(bool isSecure,
         case CT_ADAPTER_RFCOMM_BTEDR:
             OIC_LOG(ERROR, TAG, "Not supported connectivity adapter.");
             return false;
-            break;
         default:
             OIC_LOG(ERROR, TAG, "Unknown connectivity adapter.");
             return false;
@@ -676,118 +675,111 @@ static OCStackApplicationResult DeviceDiscoveryHandler(void *ctx, OCDoHandle UNU
         return OC_STACK_KEEP_TRANSACTION;
     }
     (void)UNUSED;
-    if (clientResponse)
+
+    if (!clientResponse)
     {
-        if  (NULL == clientResponse->payload)
-        {
-            OIC_LOG(INFO, TAG, "Skiping Null payload");
-            return OC_STACK_KEEP_TRANSACTION;
-        }
-        if (OC_STACK_OK != clientResponse->result)
-        {
-            OIC_LOG(INFO, TAG, "Error in response");
-            return OC_STACK_KEEP_TRANSACTION;
-        }
-        else
-        {
-            if (PAYLOAD_TYPE_SECURITY != clientResponse->payload->type)
-            {
-                OIC_LOG(INFO, TAG, "Unknown payload type");
-                return OC_STACK_KEEP_TRANSACTION;
-            }
+        OIC_LOG(INFO, TAG, "Skiping Null response");
+        return OC_STACK_KEEP_TRANSACTION;
+    }
 
-            OicSecDoxm_t *ptrDoxm = NULL;
-            uint8_t *payload = ((OCSecurityPayload*)clientResponse->payload)->securityData;
-            size_t size = ((OCSecurityPayload*)clientResponse->payload)->payloadSize;
+    if  (NULL == clientResponse->payload)
+    {
+        OIC_LOG(INFO, TAG, "Skiping Null payload");
+        return OC_STACK_KEEP_TRANSACTION;
+    }
+    if (OC_STACK_OK != clientResponse->result)
+    {
+        OIC_LOG(INFO, TAG, "Error in response");
+        return OC_STACK_KEEP_TRANSACTION;
+    }
 
-            OCStackResult res = CBORPayloadToDoxm(payload, size, &ptrDoxm);
-            if ((NULL == ptrDoxm) || (OC_STACK_OK != res))
-            {
-                OIC_LOG(INFO, TAG, "Ignoring malformed CBOR");
-                return OC_STACK_KEEP_TRANSACTION;
-            }
-            else
-            {
-                OIC_LOG(DEBUG, TAG, "Successfully converted doxm cbor to bin.");
+    if (PAYLOAD_TYPE_SECURITY != clientResponse->payload->type)
+    {
+        OIC_LOG(INFO, TAG, "Unknown payload type");
+        return OC_STACK_KEEP_TRANSACTION;
+    }
 
-                //If this is owend device discovery we have to filter out the responses.
-                DiscoveryInfo* pDInfo = (DiscoveryInfo*)ctx;
-                OCProvisionDev_t **ppDevicesList = &pDInfo->pCandidateList;
+    OicSecDoxm_t *ptrDoxm = NULL;
+    uint8_t *payload = ((OCSecurityPayload*)clientResponse->payload)->securityData;
+    size_t size = ((OCSecurityPayload*)clientResponse->payload)->payloadSize;
 
-                // Get my device ID from doxm resource
-                OicUuid_t myId;
-                memset(&myId, 0, sizeof(myId));
-                OCStackResult res = GetDoxmDevOwnerId(&myId);
-                if(OC_STACK_OK != res)
-                {
-                    OIC_LOG(ERROR, TAG, "Error while getting my device ID.");
-                    DeleteDoxmBinData(ptrDoxm);
-                    return OC_STACK_KEEP_TRANSACTION;
-                }
+    OCStackResult res = CBORPayloadToDoxm(payload, size, &ptrDoxm);
+    if ((NULL == ptrDoxm) || (OC_STACK_OK != res))
+    {
+        OIC_LOG(INFO, TAG, "Ignoring malformed CBOR");
+        return OC_STACK_KEEP_TRANSACTION;
+    }
 
-                // If this is owned discovery response but owner is not me then discard it.
-                if( (pDInfo->isOwnedDiscovery) &&
-                    (0 != memcmp(&ptrDoxm->owner.id, &myId.id, sizeof(myId.id))) )
-                {
-                    OIC_LOG(DEBUG, TAG, "Discovered device is not owend by me");
-                    DeleteDoxmBinData(ptrDoxm);
-                    return OC_STACK_KEEP_TRANSACTION;
-                }
+    OIC_LOG(DEBUG, TAG, "Successfully converted doxm cbor to bin.");
 
-                res = GetDoxmDeviceID(&myId);
-                if(OC_STACK_OK != res)
-                {
-                    OIC_LOG(ERROR, TAG, "Error while getting my UUID.");
-                    DeleteDoxmBinData(ptrDoxm);
-                    return OC_STACK_KEEP_TRANSACTION;
-                }
-                //if targetId and discovered deviceID are different, discard it
-                if ((pDInfo->isSingleDiscovery) &&
-                    (0 != memcmp(&ptrDoxm->deviceID.id, &pDInfo->targetId->id, sizeof(pDInfo->targetId->id))) )
-                {
-                    OIC_LOG(DEBUG, TAG, "Discovered device is not target device");
-                    DeleteDoxmBinData(ptrDoxm);
-                    return OC_STACK_KEEP_TRANSACTION;
-                }
-                //if this is owned discovery and this is PT's reply, discard it
-                if (((pDInfo->isSingleDiscovery) || (pDInfo->isOwnedDiscovery)) &&
-                        (0 == memcmp(&ptrDoxm->deviceID.id, &myId.id, sizeof(myId.id))) )
-                {
-                    OIC_LOG(DEBUG, TAG, "discarding provision tool's reply");
-                    DeleteDoxmBinData(ptrDoxm);
-                    return OC_STACK_KEEP_TRANSACTION;
-                }
+    //If this is owend device discovery we have to filter out the responses.
+    DiscoveryInfo* pDInfo = (DiscoveryInfo*)ctx;
+    OCProvisionDev_t **ppDevicesList = &pDInfo->pCandidateList;
 
-                res = AddDevice(ppDevicesList, &clientResponse->devAddr,
-                        clientResponse->connType, ptrDoxm);
-                if (OC_STACK_OK != res)
-                {
-                    OIC_LOG(ERROR, TAG, "Error while adding data to linkedlist.");
-                    DeleteDoxmBinData(ptrDoxm);
-                    return OC_STACK_KEEP_TRANSACTION;
-                }
+    // Get my device ID from doxm resource
+    OicUuid_t myId;
+    memset(&myId, 0, sizeof(myId));
+    res = GetDoxmDevOwnerId(&myId);
+    if(OC_STACK_OK != res)
+    {
+        OIC_LOG(ERROR, TAG, "Error while getting my device ID.");
+        DeleteDoxmBinData(ptrDoxm);
+        return OC_STACK_KEEP_TRANSACTION;
+    }
 
-                res = SecurePortDiscovery(pDInfo, clientResponse);
-                if(OC_STACK_OK != res)
-                {
-                    OIC_LOG(ERROR, TAG, "Failed to SecurePortDiscovery");
-                    DeleteDoxmBinData(ptrDoxm);
-                    return OC_STACK_KEEP_TRANSACTION;
-                }
+    // If this is owned discovery response but owner is not me then discard it.
+    if( (pDInfo->isOwnedDiscovery) &&
+        (0 != memcmp(&ptrDoxm->owner.id, &myId.id, sizeof(myId.id))) )
+    {
+        OIC_LOG(DEBUG, TAG, "Discovered device is not owend by me");
+        DeleteDoxmBinData(ptrDoxm);
+        return OC_STACK_KEEP_TRANSACTION;
+    }
 
-                OIC_LOG(INFO, TAG, "Exiting ProvisionDiscoveryHandler.");
-            }
+    res = GetDoxmDeviceID(&myId);
+    if(OC_STACK_OK != res)
+    {
+        OIC_LOG(ERROR, TAG, "Error while getting my UUID.");
+        DeleteDoxmBinData(ptrDoxm);
+        return OC_STACK_KEEP_TRANSACTION;
+    }
+    //if targetId and discovered deviceID are different, discard it
+    if ((pDInfo->isSingleDiscovery) &&
+        (0 != memcmp(&ptrDoxm->deviceID.id, &pDInfo->targetId->id, sizeof(pDInfo->targetId->id))) )
+    {
+        OIC_LOG(DEBUG, TAG, "Discovered device is not target device");
+        DeleteDoxmBinData(ptrDoxm);
+        return OC_STACK_KEEP_TRANSACTION;
+    }
+    //if this is owned discovery and this is PT's reply, discard it
+    if (((pDInfo->isSingleDiscovery) || (pDInfo->isOwnedDiscovery)) &&
+            (0 == memcmp(&ptrDoxm->deviceID.id, &myId.id, sizeof(myId.id))) )
+    {
+        OIC_LOG(DEBUG, TAG, "discarding provision tool's reply");
+        DeleteDoxmBinData(ptrDoxm);
+        return OC_STACK_KEEP_TRANSACTION;
+    }
 
-            return  OC_STACK_KEEP_TRANSACTION;
-        }
+    res = AddDevice(ppDevicesList, &clientResponse->devAddr,
+            clientResponse->connType, ptrDoxm);
+    if (OC_STACK_OK != res)
+    {
+        OIC_LOG(ERROR, TAG, "Error while adding data to linkedlist.");
+        DeleteDoxmBinData(ptrDoxm);
+        return OC_STACK_KEEP_TRANSACTION;
     }
-    else
+
+    res = SecurePortDiscovery(pDInfo, clientResponse);
+    if(OC_STACK_OK != res)
     {
-        OIC_LOG(INFO, TAG, "Skiping Null response");
+        OIC_LOG(ERROR, TAG, "Failed to SecurePortDiscovery");
+        DeleteDoxmBinData(ptrDoxm);
         return OC_STACK_KEEP_TRANSACTION;
     }
 
-    return  OC_STACK_DELETE_TRANSACTION;
+    OIC_LOG(INFO, TAG, "Exiting ProvisionDiscoveryHandler.");
+
+    return  OC_STACK_KEEP_TRANSACTION;
 }
 
 static void DeviceDiscoveryDeleteHandler(void *ctx)
index b00bac2..3952bc9 100644 (file)
@@ -309,7 +309,6 @@ bool DPGenerateQuery(bool isSecure,
         case CT_ADAPTER_RFCOMM_BTEDR:
             OIC_LOG(ERROR, TAG, "Not supported connectivity adapter.");
             return false;
-            break;
 #endif
         default:
             OIC_LOG(ERROR, TAG, "Unknown connectivity adapter.");
index 2029b8c..640ab72 100644 (file)
@@ -525,7 +525,6 @@ static bool OCRepPayloadSetProp(OCRepPayload* payload, const char* name,
         case OCREP_PROP_BYTE_STRING:
                val->ocByteStr = *(OCByteString*)value;
                return val->ocByteStr.bytes != NULL;
-               break;
         case OCREP_PROP_NULL:
                return val != NULL;
         case OCREP_PROP_ARRAY:
index 1b31142..5e06e02 100644 (file)
@@ -59,10 +59,8 @@ namespace OC
             {
             case ServiceType::InProc:
                 return std::make_shared<InProcClientWrapper>(csdkLock, cfg);
-                break;
             case ServiceType::OutOfProc:
                 return std::make_shared<OutOfProcClientWrapper>(csdkLock, cfg);
-                break;
             }
                        return nullptr;
         }
@@ -74,7 +72,6 @@ namespace OC
             {
             case ServiceType::InProc:
                 return std::make_shared<InProcServerWrapper>(csdkLock, cfg);
-                break;
             case ServiceType::OutOfProc:
                 throw OC::OCException(OC::Exception::SVCTYPE_OUTOFPROC, OC_STACK_NOTIMPL);
                 break;
index bbf0907..ba637ad 100644 (file)
@@ -432,14 +432,12 @@ namespace OC
     std::string OCRepresentation::payload_array_helper_copy<std::string>(
             size_t index, const OCRepPayloadValue* pl)
     {
-        if (pl->arr.strArray[index])
+        if (pl && pl->arr.strArray[index])
         {
             return std::string(pl->arr.strArray[index]);
         }
-        else
-        {
-            return std::string{};
-        }
+
+        return std::string{};
     }
 
     template<>
index 6d2d261..415d9c9 100644 (file)
@@ -105,6 +105,11 @@ namespace OCPlatformTest
 
     bool OCResourcePayloadAddStringLL(OCStringLL **stringLL, std::string value)
     {
+        if (!stringLL)
+        {
+            return false;
+        }
+
         char *dup = NULL;
         DuplicateString(&dup, value);
         if (!*stringLL)
@@ -124,7 +129,6 @@ namespace OCPlatformTest
             temp->next->value = dup;
             return true;
         }
-        return false;
     }
 
     OCResourceHandle RegisterResource(std::string uri, std::string type, std::string iface)