Fix a defect detected by static code analyzer 67/18967/4
authorJaewook Jung <jw0213.jung@samsung.com>
Fri, 14 Apr 2017 05:12:35 +0000 (14:12 +0900)
committerUze Choi <uzchoi@samsung.com>
Wed, 19 Apr 2017 08:05:49 +0000 (08:05 +0000)
 - remove a unreachable code
 - add a NULL checking before strcmp()

Change-Id: I459e1ab232d10affd0c0e8b1cbea340ca11fb9a2
Signed-off-by: Jaewook Jung <jw0213.jung@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/18967
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: Dan Mihai <Daniel.Mihai@microsoft.com>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
resource/csdk/stack/src/occonnectionmanager.c
resource/csdk/stack/src/ocpayloadconvert.c

index 269378d..57b7a9c 100755 (executable)
@@ -281,7 +281,6 @@ static OCStackResult OCCMFindResource()
 {
     OIC_LOG_V(INFO, TAG, "%s", __func__);
 
-    OCQualityOfService qos = OC_LOW_QOS;
     char szQueryUri[MAX_QUERY_LENGTH] = { 0 };
     snprintf(szQueryUri, sizeof(szQueryUri) - 1, "%s%c", OC_RSRVD_WELL_KNOWN_URI, '\0');
 
@@ -292,8 +291,7 @@ static OCStackResult OCCMFindResource()
 
     OCStackResult ret = OCDoResource(NULL, OC_REST_DISCOVER, szQueryUri,
                                      NULL, 0, CT_DEFAULT | CT_IP_USE_V4,
-                                     (qos == OC_HIGH_QOS) ? OC_HIGH_QOS : OC_LOW_QOS,
-                                     &cbData, NULL, 0);
+                                     OC_LOW_QOS, &cbData, NULL, 0);
     if (OC_STACK_OK != ret)
     {
         OIC_LOG(ERROR, TAG, "OCStack resource error");
index 5cdbf55..ba0a4fd 100755 (executable)
@@ -423,7 +423,13 @@ static int64_t OCConvertDiscoveryPayloadCbor(OCDiscoveryPayload *payload,
         err |= cbor_encoder_create_array(&rootMap, &linkArray, CborIndefiniteLength);
         VERIFY_CBOR_SUCCESS(TAG, err, "Failed setting links array");
 
-        bool isSelf = !strcmp(payload->sid, OCGetServerInstanceIDString());
+        bool isSelf = false;
+        const char *deviceId = OCGetServerInstanceIDString();
+        if (NULL != deviceId)
+        {
+            isSelf = !strcmp(payload->sid, deviceId);
+        }
+
         for (size_t i = 0; i < resourceCount; ++i)
         {
             OCResourcePayload *resource = OCDiscoveryPayloadGetResource(payload, i);