Fix 2 warnings in C Provisioning Module
authorWoochul Shim <woochul.shim@samsung.com>
Tue, 15 Sep 2015 00:11:51 +0000 (09:11 +0900)
committerSachin Agrawal <sachin.agrawal@intel.com>
Tue, 15 Sep 2015 16:45:10 +0000 (16:45 +0000)
- Comparision between size_t and int type incurs warning.
  Add typecast of int when int is zero or positive value.

Change-Id: I967c673fdc12e0ac8028477a4ff4573cf4596172
Signed-off-by: Woochul Shim <woochul.shim@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/2533
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Sachin Agrawal <sachin.agrawal@intel.com>
resource/csdk/security/provisioning/src/pmutility.c
resource/csdk/security/provisioning/src/secureresourceprovider.c

index 3708430..c89ff04 100644 (file)
@@ -357,11 +357,18 @@ bool PMGenerateQuery(bool isSecure,
                     OC_LOG(ERROR, TAG, "Unknown address format.");
                     return false;
             }
-            if(snRet >= bufferSize)
+            // snprintf return value check
+            if (snRet < 0)
             {
-                OC_LOG(ERROR, TAG, "PMGenerateQuery : URI is too long");
+                OC_LOG_V(ERROR, TAG, "PMGenerateQuery : Error (snprintf) %d\n", snRet);
                 return false;
             }
+            else if ((size_t)snRet >= bufferSize)
+            {
+                OC_LOG_V(ERROR, TAG, "PMGenerateQuery : Truncated (snprintf) %d\n", snRet);
+                return false;
+            }
+
             break;
         // TODO: We need to verify tinyDTLS in below cases
         case CT_ADAPTER_GATT_BTLE:
index a153e06..29e9f6c 100644 (file)
@@ -601,12 +601,17 @@ static OCStackResult SendDeleteCredentialRequest(void* ctx,
                     //coaps://0.0.0.0:5684/oic/sec/cred?sub=(BASE64 ENCODED UUID)
     snRet = snprintf(reqBuf, sizeof(reqBuf), SRP_FORM_DELETE_CREDENTIAL, destDev->endpoint.addr,
                      destDev->securePort, OIC_RSRC_CRED_URI, OIC_JSON_SUBJECT_NAME, base64Buff);
-    if (snRet < 0 || snRet >= sizeof(reqBuf))
+    if (snRet < 0)
     {
         OC_LOG_V(ERROR, TAG, "SendDeleteCredentialRequest : Error (snprintf) %d\n", snRet);
-        OC_LOG(ERROR, TAG, "                              Truncated or error");
         return OC_STACK_ERROR;
     }
+    else if ((size_t)snRet >= sizeof(reqBuf))
+    {
+        OC_LOG_V(ERROR, TAG, "SendDeleteCredentialRequest : Truncated (snprintf) %d\n", snRet);
+        return OC_STACK_ERROR;
+    }
+
     OCCallbackData cbData;
     memset(&cbData, 0, sizeof(cbData));
     cbData.context = ctx;