IOT-1836 Make resource/csdk/security/provisioning W4 compliant.
authorAlex Kelley <alexke@microsoft.com>
Wed, 15 Feb 2017 23:59:02 +0000 (15:59 -0800)
committerKevin Kane <kkane@microsoft.com>
Tue, 28 Feb 2017 02:18:08 +0000 (02:18 +0000)
These changes include the following:
- Fix W4 warnings under resource/csdk/security/provisioning

Other changes to resource/csdk/security/ are tracked in the IOT-1835 code review.

Change-Id: Ibf9d1e1bc70bc37ddead0f97d38964f01d712d54
Signed-off-by: Alex Kelley <alexke@microsoft.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/17401
Reviewed-by: Kevin Kane <kkane@microsoft.com>
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
25 files changed:
build_common/windows/SConscript
resource/csdk/security/provisioning/sample/cloud/cloudCommon.c
resource/csdk/security/provisioning/sample/cloud/cloudWrapper.c
resource/csdk/security/provisioning/sample/cloud/cloudWrapper.h
resource/csdk/security/provisioning/sample/provisioningclient.c
resource/csdk/security/provisioning/sample/sampleserver_mvjustworks.cpp
resource/csdk/security/provisioning/sample/sampleserver_randompin.cpp
resource/csdk/security/provisioning/sample/subownerclient.c
resource/csdk/security/provisioning/src/cloud/aclid.c
resource/csdk/security/provisioning/src/cloud/aclinvite.c
resource/csdk/security/provisioning/src/cloud/crl.c
resource/csdk/security/provisioning/src/cloud/csr.c
resource/csdk/security/provisioning/src/credentialgenerator.c
resource/csdk/security/provisioning/src/multipleownershiptransfermanager.c
resource/csdk/security/provisioning/src/ocprovisioningmanager.c
resource/csdk/security/provisioning/src/ownershiptransfermanager.c
resource/csdk/security/provisioning/src/oxmpreconfpin.c
resource/csdk/security/provisioning/src/pmutility.c
resource/csdk/security/provisioning/src/secureresourceprovider.c
resource/csdk/security/provisioning/unittest/provisioningdatabasemanager.cpp
resource/csdk/security/provisioning/unittest/secureresourceprovider.cpp
resource/csdk/security/unittest/aclresourcetest.cpp
resource/csdk/security/unittest/crlresourcetest.cpp
resource/csdk/security/unittest/srmtestcommon.cpp
resource/csdk/security/unittests/SConscript

index 64053ea..bcd8911 100644 (file)
@@ -7,8 +7,13 @@ import os.path
 # Set common flags
 if env['CC'] == 'cl':
     # Enable warnings as errors.
-    env.AppendUnique(CCFLAGS=[
-        '/we4133'])  # C4133 incompatible type conversion
+    #  - warning C4133: incompatible type conversion
+    env.AppendUnique(CCFLAGS=['/we4133'])
+
+    # Disable the following warnings:
+    #  - warning C4127: conditional expression is constant
+    #    - Disabled due to the widespread usage in IoTivity
+    env.AppendUnique(CCFLAGS=['/wd4127'])
 
     env.AppendUnique(CCFLAGS=['/EHsc'])
 
index fd32c48..278d8d6 100644 (file)
@@ -444,8 +444,8 @@ static void userRequests(void *data)
         {
             char example[8];
             snprintf(example, sizeof(example), "%d", DEFAULT_PORT);
-            int tmp = 0;
-            readInteger(&tmp, "port number", example);
+            uint16_t tmp = 0;
+            readUInt16(&tmp, "port number", example);
             endPoint.port = tmp;
             sendDataToServer = false;
         }
index f044be7..1a0b29e 100644 (file)
@@ -116,6 +116,13 @@ void readInteger(int* item, const char* description, const char* example)
     skipSpecialCharacters();
 }
 
+void readUInt16(uint16_t* item, const char* description, const char* example)
+{
+    printf("Enter %s (f.e. %s):\n", description, example);
+    scanf("%hu", item);
+    skipSpecialCharacters();
+}
+
 /**
  * Read user input (expect array of strings)
  *
@@ -446,16 +453,16 @@ OCStackResult OCWrapperAclIndividualUpdateAce(const OCDevAddr *endPoint, OCCloud
 
         char aceid[MAX_ID_LENGTH] = { 0 };
         char subjectuuid[MAX_ID_LENGTH] = { 0 };
-        int stype = 0;
-        int permission = 0;
+        uint16_t stype = 0;
+        uint16_t permission = 0;
 
         do
         {
             readString(subjectuuid, sizeof(subjectuuid), "subjectuuid", SUBJECT_ID_EXAMPLE);
         } while (OC_STACK_OK != ConvertStrToUuid(subjectuuid, &ace->subjectuuid));
 
-        readInteger(&stype, "subject type", "0 – Device, 1 – User, 2 - Group");
-        readInteger(&permission, "permission", "6");
+        readUInt16(&stype, "subject type", "0 – Device, 1 – User, 2 - Group");
+        readUInt16(&permission, "permission", "6");
 
         ace->aceId = OICStrdup(aceid);
         ace->stype = stype;
@@ -464,7 +471,7 @@ OCStackResult OCWrapperAclIndividualUpdateAce(const OCDevAddr *endPoint, OCCloud
         int reslist_count = 0;
         readInteger(&reslist_count, "resources list count", "1");
 
-        for (int i = 0; i < reslist_count; i++)
+        for (int j = 0; j < reslist_count; j++)
         {
             OicSecRsrc_t *res = OICCalloc(1, sizeof(OicSecRsrc_t));
             if (!res)
@@ -513,8 +520,8 @@ OCStackResult OCWrapperAclIndividualUpdate(const OCDevAddr *endPoint, OCCloudRes
 
     char aceid[MAX_ID_LENGTH] = { 0 };
     char subjectuuid[MAX_ID_LENGTH] = { 0 };
-    int stype = 0;
-    int permission = 0;
+    uint16_t stype = 0;
+    uint16_t permission = 0;
 
     readString(aceid, sizeof(aceid), "ace id", ACE_ID_EXAMPLE);
     do
@@ -522,8 +529,8 @@ OCStackResult OCWrapperAclIndividualUpdate(const OCDevAddr *endPoint, OCCloudRes
         readString(subjectuuid, sizeof(subjectuuid), "subjectuuid", SUBJECT_ID_EXAMPLE);
     } while (OC_STACK_OK != ConvertStrToUuid(subjectuuid, &ace->subjectuuid));
 
-    readInteger(&stype, "subject type", "0 – Device, 1 – User, 2 - Group");
-    readInteger(&permission, "permission", "6");
+    readUInt16(&stype, "subject type", "0 – Device, 1 – User, 2 - Group");
+    readUInt16(&permission, "permission", "6");
 
     ace->stype = stype;
     ace->permission = permission;
index 4862c62..584fbb8 100644 (file)
@@ -258,6 +258,15 @@ void readString(char* item, int length, const char* description, const char* exa
 void readInteger(int* item, const char* description, const char* example);
 
 /**
+ * Read user input (expect uint16_t value)
+ *
+ * @param[out] item           uint16_t item to fill
+ * @param[in]  description    item description
+ * @param[in]  example        item example
+ */
+void readUInt16(uint16_t* item, const char* description, const char* example);
+
+/**
  * Copies whole binary file to out variable
  *
  * @param[in] list           array of strings structure
index f2f1545..0824b2f 100644 (file)
@@ -293,6 +293,9 @@ static void updateDoxmForMOTCB(void* ctx, size_t nOfRes, OCProvisionResult_t* ar
 
 static void inputPinCB(OicUuid_t deviceId, char *pin, size_t len, void *context)
 {
+    OC_UNUSED(deviceId);
+    OC_UNUSED(context);
+
     if(!pin || OXM_RANDOM_PIN_MIN_SIZE > len)
     {
         OIC_LOG(ERROR, TAG, "inputPinCB invalid parameters");
@@ -1265,6 +1268,8 @@ static int removeDeviceWithUuid(void)
 
 OCStackResult displayNumCB(void * ctx, uint8_t mutualVerifNum[MUTUAL_VERIF_NUM_LEN])
 {
+    OC_UNUSED(ctx);
+
     OIC_LOG(INFO, TAG, "IN displayMutualVerifNumCB");
     if (NULL != mutualVerifNum)
     {
@@ -1282,6 +1287,8 @@ OCStackResult displayNumCB(void * ctx, uint8_t mutualVerifNum[MUTUAL_VERIF_NUM_L
 
 OCStackResult confirmNumCB(void * ctx)
 {
+    OC_UNUSED(ctx);
+
     for (;;)
     {
         int userConfirm;
@@ -1405,7 +1412,6 @@ static int selectMultipleOwnershipTrnasferMethod(void)
         printf("     Entered Wrong Number. Please Enter Again\n");
     }
 
-    const int preconfOxm = 4;
     int oxm = 0;
     for( ; ; )
     {
@@ -1694,17 +1700,17 @@ static OicSecAcl_t* createAcl(const int dev_num)
             goto CRACL_ERROR;
         }
 
-        for(size_t i = 0; i < arrLen; i++)
+        for(size_t j = 0; j < arrLen; j++)
         {
-            printf("         Enter ResourceType[%zu] Name (e.g. core.led): ", i+1);
+            printf("         Enter ResourceType[%zu] Name (e.g. core.led): ", j+1);
             for(int ret=0; 1!=ret; )
             {
                 ret = scanf("%128s", rsrc_in);  // '128' is ACL_RESRC_MAX_LEN
                 for( ; 0x20<=getchar(); );  // for removing overflow garbages
                                             // '0x20<=code' is character region
             }
-            rsrc->types[i] = OICStrdup(rsrc_in);
-            if(!rsrc->types[i])
+            rsrc->types[j] = OICStrdup(rsrc_in);
+            if(!rsrc->types[j])
             {
                 OIC_LOG(ERROR, TAG, "createAcl: OICStrdup error return");
                 goto CRACL_ERROR;
@@ -1735,17 +1741,17 @@ static OicSecAcl_t* createAcl(const int dev_num)
             goto CRACL_ERROR;
         }
 
-        for(size_t i = 0; i < arrLen; i++)
+        for(size_t j = 0; j < arrLen; j++)
         {
-            printf("         Enter Interface[%zu] Name (e.g. oic.if.baseline): ", i+1);
+            printf("         Enter Interface[%zu] Name (e.g. oic.if.baseline): ", j+1);
             for(int ret=0; 1!=ret; )
             {
                 ret = scanf("%128s", rsrc_in);  // '128' is ACL_RESRC_MAX_LEN
                 for( ; 0x20<=getchar(); );  // for removing overflow garbages
                                             // '0x20<=code' is character region
             }
-            rsrc->interfaces[i] = OICStrdup(rsrc_in);
-            if(!rsrc->interfaces[i])
+            rsrc->interfaces[j] = OICStrdup(rsrc_in);
+            if(!rsrc->interfaces[j])
             {
                 OIC_LOG(ERROR, TAG, "createAcl: OICStrdup error return");
                 goto CRACL_ERROR;
@@ -2053,6 +2059,9 @@ const char* getResult(OCStackResult result)
 OCStackApplicationResult getReqCB(void* ctx, OCDoHandle handle,
     OCClientResponse* clientResponse)
 {
+    OC_UNUSED(ctx);
+    OC_UNUSED(handle);
+
     if (clientResponse == NULL)
     {
         OIC_LOG(INFO, TAG, "getReqCB received NULL clientResponse");
@@ -2257,26 +2266,26 @@ static int waitCallbackRet(void)
 
 static int selectTwoDiffNum(int* a, int* b, const int max, const char* str)
 {
-    if(!a || !b || 2>max || !str)
+    if(!a || !b || (2 > max) || !str)
     {
         return -1;
     }
 
     for( ; ; )
     {
-        for(int i=0; 2>i; ++i)
+        for(int i = 0; 2 > i; ++i)
         {
-            int* num = 0==i?a:b;
+            int* num = (0 == i) ? a : b;
             for( ; ; )
             {
-                printf("   > Enter Device[%d] Number, %s: ", i+1, str);
-                for(int ret=0; 1!=ret; )
+                printf("   > Enter Device[%d] Number, %s: ", (i + 1), str);
+                for(int ret = 0; 1 != ret;)
                 {
                     ret = scanf("%d", num);
                     for( ; 0x20<=getchar(); );  // for removing overflow garbages
                                                 // '0x20<=code' is character region
                 }
-                if(0<*num && max>=*num)
+                if((0 < *num) && (max >= *num))
                 {
                     break;
                 }
@@ -2289,8 +2298,6 @@ static int selectTwoDiffNum(int* a, int* b, const int max, const char* str)
             return 0;
         }
     }
-
-    return -1;
 }
 
 #ifdef __WITH_TLS__
index 2bdc8fd..e35a1e6 100644 (file)
@@ -397,8 +397,10 @@ OCEntityHandlerCb (OCEntityHandlerFlag flag,
     return ehResult;
 }
 
-OCStackResult displayNumCB(void * ctx, uint8_t mutualVerifNum[MUTUAL_VERIF_NUM_LEN])
+OCStackResult displayNumCB(void *ctx, uint8_t mutualVerifNum[MUTUAL_VERIF_NUM_LEN])
 {
+    OC_UNUSED(ctx);
+
     OIC_LOG(INFO, TAG, "IN displayNumCB");
     OIC_LOG(INFO, TAG, "############ mutualVerifNum ############");
     OIC_LOG_BUFFER(INFO, TAG, mutualVerifNum, MUTUAL_VERIF_NUM_LEN);
@@ -407,8 +409,10 @@ OCStackResult displayNumCB(void * ctx, uint8_t mutualVerifNum[MUTUAL_VERIF_NUM_L
     return OC_STACK_OK;
 }
 
-OCStackResult confirmNumCB(void * ctx)
+OCStackResult confirmNumCB(void *ctx)
 {
+    OC_UNUSED(ctx);
+
     for (;;)
     {
         int userConfirm;
index 45cc4f4..f67caf8 100644 (file)
@@ -456,6 +456,8 @@ FILE* server_fopen(const char *path, const char *mode)
 
 void DisplayPinCB(char *pin, size_t pinSize, void *context)
 {
+    OC_UNUSED(context);
+
     if(NULL == pin || pinSize <= 0)
     {
         OIC_LOG(INFO, TAG, "Invalid PIN");
@@ -514,7 +516,7 @@ int main()
     {
         printf("Press 'G' to generate random PIN...\n");
         printf("Press 'E' to exit...\n");
-        char in = getchar();
+        char in = (char)getchar();
         if('G' == in || 'g' == in)
         {
             char ranPin[OXM_RANDOM_PIN_MAX_SIZE + 1] = {0};
index 3e5803d..ef26f9c 100644 (file)
@@ -179,6 +179,9 @@ static void provisionAclCB(void* ctx, size_t nOfRes, OCProvisionResult_t* arr, b
 // response handler for LED requests.
 static OCStackApplicationResult LedCB(void *ctx, OCDoHandle UNUSED, OCClientResponse *clientResponse)
 {
+    OC_UNUSED(ctx);
+    OC_UNUSED(UNUSED);
+
     if(clientResponse)
     {
         if(OC_STACK_OK == clientResponse->result)
@@ -944,7 +947,6 @@ int main()
 
     // main loop for provisioning manager
     int mnNum = 0;
-    int selDevNum = 0;
     for( ; ; )
     {
         printf("\n");
index e2424db..6ce5ec3 100644 (file)
@@ -276,13 +276,13 @@ OCStackResult OCCloudAclIndividualUpdateAce(void* ctx,
 
     LL_FOREACH((cloudAce_t*)aces, ace)
     {
-        OCRepPayload *payload = OCRepPayloadCreate();
-        if (!payload)
+        OCRepPayload *acePayload = OCRepPayloadCreate();
+        if (!acePayload)
         {
             OIC_LOG_V(DEBUG, TAG, "Can't allocate memory for helperPayload[i]");
             goto no_memory;
         }
-        helperPayload[i++] = payload;
+        helperPayload[i++] = acePayload;
 
         char *uuid = NULL;
         if (OC_STACK_OK != ConvertUuidToStr(&ace->subjectuuid, &uuid))
@@ -290,9 +290,9 @@ OCStackResult OCCloudAclIndividualUpdateAce(void* ctx,
             OIC_LOG(ERROR, TAG, "Can't convert subjectuuid to string");
         }
 
-        OCRepPayloadSetPropString(payload, OC_RSRVD_SUBJECT_UUID, (const char *)uuid);
-        OCRepPayloadSetPropInt(payload, OC_RSRVD_SUBJECT_TYPE, ace->stype);
-        OCRepPayloadSetPropInt(payload, OC_RSRVD_PERMISSION_MASK, ace->permission);
+        OCRepPayloadSetPropString(acePayload, OC_RSRVD_SUBJECT_UUID, (const char *)uuid);
+        OCRepPayloadSetPropInt(acePayload, OC_RSRVD_SUBJECT_TYPE, ace->stype);
+        OCRepPayloadSetPropInt(acePayload, OC_RSRVD_PERMISSION_MASK, ace->permission);
 
         OICFree(uuid);
 
@@ -318,26 +318,26 @@ OCStackResult OCCloudAclIndividualUpdateAce(void* ctx,
 
         LL_FOREACH(ace->resources, res)
         {
-            OCRepPayload *payload = OCRepPayloadCreate();
-            if (!payload)
+            OCRepPayload *aceResourcePayload = OCRepPayloadCreate();
+            if (!aceResourcePayload)
             {
                 OIC_LOG_V(DEBUG, TAG, "Can't allocate memory for helperPayload2[j]");
                 goto no_memory;
             }
-            helperPayload2[j++] = payload;
+            helperPayload2[j++] = aceResourcePayload;
 
-            OCRepPayloadSetPropString(payload, OC_RSRVD_HREF, res->href);
+            OCRepPayloadSetPropString(aceResourcePayload, OC_RSRVD_HREF, res->href);
 
             dimensions[0] = res->typeLen;
-            OCRepPayloadSetStringArray(payload, OC_RSRVD_RESOURCE_TYPE,
+            OCRepPayloadSetStringArray(aceResourcePayload, OC_RSRVD_RESOURCE_TYPE,
                                        (const char **)res->types, dimensions);
 
             dimensions[0] = res->interfaceLen;
-            OCRepPayloadSetStringArray(payload, OC_RSRVD_INTERFACE,
+            OCRepPayloadSetStringArray(aceResourcePayload, OC_RSRVD_INTERFACE,
                                        (const char **)res->interfaces, dimensions);
         }
         dimensions[0] = reslist_count;
-        OCRepPayloadSetPropObjectArray(payload, OC_RSRVD_RESOURCES,
+        OCRepPayloadSetPropObjectArray(acePayload, OC_RSRVD_RESOURCES,
                 (const OCRepPayload **)helperPayload2, dimensions);
     }
     dimensions[0] = acllist_count;
@@ -411,13 +411,13 @@ OCStackResult OCCloudAclIndividualUpdate(void* ctx,
 
     LL_FOREACH((cloudAce_t*)aces, ace)
     {
-        OCRepPayload *payload = OCRepPayloadCreate();
-        if (!payload)
+        OCRepPayload *acePayload = OCRepPayloadCreate();
+        if (!acePayload)
         {
             OIC_LOG_V(DEBUG, TAG, "Can't allocate memory for helperPayload[i]");
             goto no_memory;
         }
-        helperPayload[i++] = payload;
+        helperPayload[i++] = acePayload;
 
         char *uuid = NULL;
         if (OC_STACK_OK != ConvertUuidToStr(&ace->subjectuuid, &uuid))
@@ -425,9 +425,9 @@ OCStackResult OCCloudAclIndividualUpdate(void* ctx,
             OIC_LOG(ERROR, TAG, "Can't convert subjectuuid to string");
         }
 
-        OCRepPayloadSetPropString(payload, OC_RSRVD_SUBJECT_UUID, (const char *)uuid);
-        OCRepPayloadSetPropInt(payload, OC_RSRVD_SUBJECT_TYPE, ace->stype);
-        OCRepPayloadSetPropInt(payload, OC_RSRVD_PERMISSION_MASK, ace->permission);
+        OCRepPayloadSetPropString(acePayload, OC_RSRVD_SUBJECT_UUID, (const char *)uuid);
+        OCRepPayloadSetPropInt(acePayload, OC_RSRVD_SUBJECT_TYPE, ace->stype);
+        OCRepPayloadSetPropInt(acePayload, OC_RSRVD_PERMISSION_MASK, ace->permission);
 
         OICFree(uuid);
 
@@ -453,26 +453,26 @@ OCStackResult OCCloudAclIndividualUpdate(void* ctx,
 
         LL_FOREACH(ace->resources, res)
         {
-            OCRepPayload *payload = OCRepPayloadCreate();
-            if (!payload)
+            OCRepPayload *aceResourcePayload = OCRepPayloadCreate();
+            if (!aceResourcePayload)
             {
                 OIC_LOG_V(DEBUG, TAG, "Can't allocate memory for helperPayload2[j]");
                 goto no_memory;
             }
-            helperPayload2[j++] = payload;
+            helperPayload2[j++] = aceResourcePayload;
 
-            OCRepPayloadSetPropString(payload, OC_RSRVD_HREF, res->href);
+            OCRepPayloadSetPropString(aceResourcePayload, OC_RSRVD_HREF, res->href);
 
             dimensions[0] = res->typeLen;
-            OCRepPayloadSetStringArray(payload, OC_RSRVD_RESOURCE_TYPE,
+            OCRepPayloadSetStringArray(aceResourcePayload, OC_RSRVD_RESOURCE_TYPE,
                                        (const char **)res->types, dimensions);
 
             dimensions[0] = res->interfaceLen;
-            OCRepPayloadSetStringArray(payload, OC_RSRVD_INTERFACE,
+            OCRepPayloadSetStringArray(aceResourcePayload, OC_RSRVD_INTERFACE,
                                        (const char **)res->interfaces, dimensions);
         }
         dimensions[0] = reslist_count;
-        OCRepPayloadSetPropObjectArray(payload, OC_RSRVD_RESOURCES,
+        OCRepPayloadSetPropObjectArray(acePayload, OC_RSRVD_RESOURCES,
                 (const OCRepPayload **)helperPayload2, dimensions);
     }
     dimensions[0] = acllist_count;
index 78d1097..6bf8370 100644 (file)
@@ -45,10 +45,10 @@ static OCStackResult parseInvitePayload(const OCRepPayload *payload, const char
 {
     OCStackResult result = OC_STACK_NO_MEMORY;
     size_t dimensions[MAX_REP_ARRAY_DEPTH] = { 0 };
-    OCRepPayload **heplerPayload  = NULL;
+    OCRepPayload **helperPayload  = NULL;
     size_t i = 0;
 
-    if (!OCRepPayloadGetPropObjectArray(payload, name, &heplerPayload, dimensions))
+    if (!OCRepPayloadGetPropObjectArray(payload, name, &helperPayload, dimensions))
     {
         OIC_LOG_V(ERROR, TAG, "Can't get: %s", name);
         return OC_STACK_MALFORMED_RESPONSE;
@@ -78,22 +78,22 @@ static OCStackResult parseInvitePayload(const OCRepPayload *payload, const char
 
     for (i = 0; i < gidlist->length; i++)
     {
-        const OCRepPayload *payload = heplerPayload[i];
+        const OCRepPayload *gidPayload = helperPayload[i];
 
-        if (!OCRepPayloadGetPropString(payload, OC_RSRVD_GROUP_ID, &gidlist->array[i]))
+        if (!OCRepPayloadGetPropString(gidPayload, OC_RSRVD_GROUP_ID, &gidlist->array[i]))
         {
             OIC_LOG_V(ERROR, TAG, "Can't get: %s", OC_RSRVD_GROUP_ID);
             result = OC_STACK_MALFORMED_RESPONSE;
             goto exit;
         }
 
-        if (!OCRepPayloadGetPropString(payload, OC_RSRVD_MEMBER_ID, &midlist->array[i]))
+        if (!OCRepPayloadGetPropString(gidPayload, OC_RSRVD_MEMBER_ID, &midlist->array[i]))
         {
             OIC_LOG_V(ERROR, TAG, "Can't get: %s", OC_RSRVD_MEMBER_ID);
             result = OC_STACK_MALFORMED_RESPONSE;
             goto exit;
         }
-        OCRepPayloadDestroy(heplerPayload[i]);
+        OCRepPayloadDestroy(helperPayload[i]);
     }
 
     result = OC_STACK_OK;
@@ -106,10 +106,10 @@ exit:
 
         for (size_t k = i; k < gidlist->length; k++)
         {
-            OCRepPayloadDestroy(heplerPayload[i]);
+            OCRepPayloadDestroy(helperPayload[i]);
         }
     }
-    OICFree(heplerPayload);
+    OICFree(helperPayload);
     return result;
 }
 
@@ -237,7 +237,8 @@ OCStackResult OCCloudAclInviteUser(void* ctx,
     //add next fields if they were filled
     if (userId) OCRepPayloadSetPropString(payload, OC_RSRVD_USER_UUID, userId);
 
-    size_t dimensions[MAX_REP_ARRAY_DEPTH] = {groupIds->length, 0, 0};
+    size_t dimensions[MAX_REP_ARRAY_DEPTH] = {0, 0, 0};
+    dimensions[0] = groupIds->length;
     OCRepPayloadSetPropObjectArray(payload, OC_RSRVD_INVITE,
             (const struct OCRepPayload **)heplerPayload, dimensions);
 
@@ -327,8 +328,8 @@ OCStackResult OCCloudAclCancelInvitation(void* ctx,
 
     if (userId)
     {
-        size_t len = strlen(uri);
-        snprintf(uri + len, MAX_URI_LENGTH - len, "?%s=%s", OC_RSRVD_USER_UUID, userId);
+        len = strlen(uri);
+        snprintf((uri + len), (MAX_URI_LENGTH - len), "?%s=%s", OC_RSRVD_USER_UUID, userId);
     }
 
     len = strlen(uri);
index 3ed179c..f9798e9 100644 (file)
@@ -155,7 +155,8 @@ OCStackResult OCCloudPostCRL(void* ctx,
     //add next fields if they were filled
     if (serialNumbers)
     {
-        size_t dimensions[MAX_REP_ARRAY_DEPTH] = {serialNumbers->length, 0 ,0};
+        size_t dimensions[MAX_REP_ARRAY_DEPTH] = {0, 0, 0};
+        dimensions[0] = serialNumbers->length;
         OCRepPayloadSetStringArray(payload, OC_RSRVD_SERIAL_NUMBERS,
                                    (const char**)serialNumbers->array, dimensions);
 
index 2bb6475..5df4655 100644 (file)
@@ -114,7 +114,7 @@ static int ecdsaGenKeypair(mbedtls_pk_context * pk)
     mbedtls_ctr_drbg_init(&ctr_drbg);
     mbedtls_entropy_init(&entropy);
     if (0 != mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func,
-                                   &entropy, PERSONALIZATION_STRING, sizeof(PERSONALIZATION_STRING)))
+                                   &entropy, (const unsigned char*)PERSONALIZATION_STRING, sizeof(PERSONALIZATION_STRING)))
     {
         OIC_LOG(ERROR, TAG, "Seed initialization failed!");
         OIC_LOG_V(DEBUG, TAG, "Out %s", __func__);
@@ -211,8 +211,9 @@ static int GenerateCSR(char *subject, OCByteString *csr)
     // Initialize the DRBG context
     mbedtls_ctr_drbg_init(&ctr_drbg);
     mbedtls_entropy_init(&entropy);
+
     result = mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func,
-             &entropy, PERSONALIZATION_STRING, sizeof(PERSONALIZATION_STRING));
+             &entropy, (const unsigned char*)PERSONALIZATION_STRING, sizeof(PERSONALIZATION_STRING));
     if (result < 0)
     {
         OIC_LOG(ERROR, TAG, "Seed initialization failed!");
@@ -327,12 +328,11 @@ static OCStackResult HandleCertificateIssueRequest(void *ctx, void **data, OCCli
     }
     else
     {
-        OicSecKey_t key =
-        {
-            g_privateKey.bytes,
-            g_privateKey.len,
-            OIC_ENCODING_DER
-        };
+        OicSecKey_t key;
+        memset(&key, 0, sizeof(key));
+        key.data = g_privateKey.bytes;
+        key.len = g_privateKey.len;
+        key.encoding = OIC_ENCODING_DER;
 
         uint16_t credId;
         result = SRPSaveOwnCertChain(&cert, &key, &credId);
@@ -420,7 +420,11 @@ OCStackResult OCCloudCertificateIssueRequest(void* ctx,
 
     OCRepPayloadSetPropString(payload, OC_RSRVD_DEVICE_ID, deviceId);
 
-    OicSecKey_t csr = {.data = request.bytes, .len = request.len, .encoding = OIC_ENCODING_DER};
+    OicSecKey_t csr;
+    memset(&csr, 0, sizeof(csr));
+    csr.data = request.bytes;
+    csr.len = request.len;
+    csr.encoding = OIC_ENCODING_DER;
 
     OCRepPayloadSetPropPubDataType(payload, OC_RSRVD_CSR, &csr);
 
index a70cf8b..afc682c 100644 (file)
@@ -55,7 +55,12 @@ OCStackResult PMGeneratePairWiseCredentials(OicSecCredType_t type, size_t keySiz
 
     uint8_t *privData = (uint8_t *)OICCalloc(privDataKeySize, sizeof(uint8_t));
     VERIFY_NOT_NULL(TAG, privData, ERROR);
-    OicSecKey_t privKey = {.data=privData, .len=keySize};
+
+    OicSecKey_t privKey;
+    memset(&privKey, 0, sizeof(privKey));
+    privKey.data = privData;
+    privKey.len = keySize;
+    privKey.encoding = OIC_ENCODING_UNKNOW;
 
     if (!OCGetRandomBytes(privData, privDataKeySize))
     {
index 374b207..45ee265 100644 (file)
@@ -262,7 +262,6 @@ OCStackResult MOTAddMOTMethod(void *ctx, OCProvisionDev_t *targetDeviceInfo,
     OCStackResult postOxmRes = OC_STACK_INVALID_PARAM;
     OicSecOxm_t* newOxms = NULL;
     uint8_t* doxmPayload = NULL;
-    size_t doxmPayloadLen = 0;
 
     OIC_LOG(DEBUG, TAG, "IN MOTAddMOTMethod");
 
@@ -407,7 +406,7 @@ OCStackResult MOTProvisionPreconfigPIN(void *ctx, const OCProvisionDev_t *target
     pinCred->privateData.len = preconfPINLen;
     pinCred->privateData.encoding = OIC_ENCODING_RAW;
     pinCred->credType = PIN_PASSWORD;
-    OICStrcpy(pinCred->subject.id, sizeof(pinCred->subject.id), WILDCARD_SUBJECT_ID.id);
+    memcpy(&pinCred->subject, &WILDCARD_SUBJECT_ID, sizeof(OicUuid_t));
 
     //Generate the security payload using updated doxm
     secPayload = (OCSecurityPayload*)OICCalloc(1, sizeof(OCSecurityPayload));
@@ -598,7 +597,6 @@ OCStackResult MOTAddPreconfigPIN(const OCProvisionDev_t *targetDeviceInfo,
 {
     OCStackResult addCredRes = OC_STACK_INVALID_PARAM;
     OicSecCred_t* pinCred = NULL;
-    bool freeFlag = true;
 
     OIC_LOG(DEBUG, TAG, "IN MOTAddPreconfigPIN");
 
@@ -672,7 +670,11 @@ static OCStackResult SaveSubOwnerPSK(OCProvisionDev_t *selectedDeviceInfo)
     }
 
     uint8_t ownerPSK[OWNER_PSK_LENGTH_128] = {0};
-    OicSecKey_t ownerKey = {ownerPSK, OWNER_PSK_LENGTH_128};
+    OicSecKey_t ownerKey;
+    memset(&ownerKey, 0, sizeof(ownerKey));
+    ownerKey.data = ownerPSK;
+    ownerKey.len = OWNER_PSK_LENGTH_128;
+    ownerKey.encoding = OIC_ENCODING_UNKNOW;
 
     //Generating SubOwnerPSK
     CAResult_t pskRet = CAGenerateOwnerPSK(&endpoint,
@@ -694,15 +696,15 @@ static OCStackResult SaveSubOwnerPSK(OCProvisionDev_t *selectedDeviceInfo)
 
         size_t outSize = 0;
         size_t b64BufSize = B64ENCODE_OUT_SAFESIZE((OWNER_PSK_LENGTH_128 + 1));
-        char* b64Buf = (uint8_t *)OICCalloc(1, b64BufSize);
+        char* b64Buf = (char*)OICCalloc(1, b64BufSize);
         VERIFY_NOT_NULL(TAG, b64Buf, ERROR);
         b64Encode(cred->privateData.data, cred->privateData.len, b64Buf, b64BufSize, &outSize);
 
-        OICFree( cred->privateData.data );
+        OICFree(cred->privateData.data);
         cred->privateData.data = (uint8_t *)OICCalloc(1, outSize + 1);
         VERIFY_NOT_NULL(TAG, cred->privateData.data, ERROR);
 
-        strncpy(cred->privateData.data, b64Buf, outSize);
+        strncpy((char*)(cred->privateData.data), b64Buf, outSize);
         cred->privateData.data[outSize] = '\0';
         cred->privateData.encoding = OIC_ENCODING_BASE64;
         cred->privateData.len = outSize;
@@ -846,7 +848,7 @@ static OCStackResult PostSubOwnerCredential(OTMContext_t* motCtx)
         memcpy(newCredential.eownerID->id, ownerId.id, sizeof(ownerId.id));
 
         //Fill private data as empty string
-        newCredential.privateData.data = "";
+        newCredential.privateData.data = (uint8_t*)"";
         newCredential.privateData.len = 0;
         newCredential.privateData.encoding = ownerCredential->privateData.encoding;
 
@@ -913,8 +915,6 @@ static void MOTDtlsHandshakeCB(const CAEndpoint_t *endpoint, const CAErrorInfo_t
 
             if(NULL != newDevDoxm)
             {
-                OicUuid_t emptyUuid = {.id={0}};
-
                 //Make sure the address matches.
                 if(strncmp(motCtx->selectedDeviceInfo->endpoint.addr,
                    endpoint->addr,
index a511c2e..31df69b 100644 (file)
@@ -437,6 +437,8 @@ OCStackResult OCProvisionDirectPairing(void* ctx, const OCProvisionDev_t *select
 #ifdef MULTIPLE_OWNER
 static void AddPreconfPinOxMCB(void* ctx, size_t nOfRes, OCProvisionResult_t *arr, bool hasError)
 {
+    OC_UNUSED(hasError);
+
     ProvPreconfPINCtx_t* provCtx = (ProvPreconfPINCtx_t*)ctx;
     if(provCtx)
     {
index 666d8d0..299496b 100755 (executable)
@@ -624,6 +624,8 @@ exit:
 static void OwnershipTransferSessionFailed(const CAEndpoint_t *endpoint,
         const CAErrorInfo_t *info, OicSecDoxm_t *newDevDoxm, OTMContext_t *otmCtx, bool emptyOwnerUuid)
 {
+    OC_UNUSED(endpoint);
+
     OIC_LOG_V(DEBUG, TAG, "IN %s", __func__);
 
     if (CA_DTLS_AUTHENTICATION_FAILURE != info->result)
@@ -768,6 +770,7 @@ static OCStackResult SaveOwnerPSK(OCProvisionDev_t *selectedDeviceInfo)
     endpoint.addr[MAX_ADDR_STR_SIZE_CA - 1] = '\0';
     endpoint.port = selectedDeviceInfo->securePort;
     endpoint.adapter = selectedDeviceInfo->endpoint.adapter;
+    uint8_t ownerPSK[OWNER_PSK_LENGTH_128] = { 0 };
 
     OicUuid_t ownerDeviceID = {.id={0}};
     if (OC_STACK_OK != GetDoxmDeviceID(&ownerDeviceID))
@@ -776,8 +779,11 @@ static OCStackResult SaveOwnerPSK(OCProvisionDev_t *selectedDeviceInfo)
         return res;
     }
 
-    uint8_t ownerPSK[OWNER_PSK_LENGTH_128] = {0};
-    OicSecKey_t ownerKey = {.data=ownerPSK, .len=OWNER_PSK_LENGTH_128, .encoding=OIC_ENCODING_RAW};
+    OicSecKey_t ownerKey;
+    memset(&ownerKey, 0, sizeof(ownerKey));
+    ownerKey.data = ownerPSK;
+    ownerKey.len = OWNER_PSK_LENGTH_128;
+    ownerKey.encoding = OIC_ENCODING_RAW;
 
     //Generating OwnerPSK
     CAResult_t pskRet = CAGenerateOwnerPSK(&endpoint,
index 4329df6..7b5d902 100644 (file)
@@ -81,7 +81,7 @@ OCStackResult LoadPreconfigPinCodeCallback(OTMContext_t *otmCtx)
     if(NULL == cred)
     {
         OicUuid_t uuid = {.id={0}};
-        OICStrcpy(uuid.id, sizeof(uuid.id), WILDCARD_SUBJECT_ID.id);
+        memcpy(&uuid, &WILDCARD_SUBJECT_ID, sizeof(OicUuid_t));
         cred = GetCredResourceData(&uuid);
         if(NULL == cred)
         {
@@ -104,7 +104,7 @@ OCStackResult LoadPreconfigPinCodeCallback(OTMContext_t *otmCtx)
             return OC_STACK_NO_MEMORY;
         }
         size_t pinLen = 0;
-        if(B64_OK != b64Decode(cred->privateData.data, cred->privateData.len, pinBuffer, pinBufLen, &pinLen))
+        if(B64_OK != b64Decode((char*)cred->privateData.data, cred->privateData.len, pinBuffer, pinBufLen, &pinLen))
         {
             OIC_LOG(ERROR, TAG, "Failed to base64 deconding for preconfig PIN");
             OICFree(pinBuffer);
index 4d5e10b..0d54ea0 100644 (file)
@@ -1261,8 +1261,6 @@ static OCStackApplicationResult MOTDeviceDiscoveryHandler(void *ctx, OCDoHandle
         OIC_LOG(INFO, TAG, "Skiping Null response");
         return OC_STACK_KEEP_TRANSACTION;
     }
-
-    return  OC_STACK_DELETE_TRANSACTION;
 }
 
 /**
index 2b110af..9c68a11 100644 (file)
@@ -774,7 +774,6 @@ OCStackResult SRPProvisionCredentials(void *ctx, OicSecCredType_t type, size_t k
             return OC_STACK_INVALID_PARAM;
         }
     }
-    return OC_STACK_ERROR;
 }
 
 /**
index b457c6d..f6cd2a0 100644 (file)
@@ -107,7 +107,7 @@ TEST(PDMAddDeviceTest, ValidUUID)
     {
         int tem = rand() % 25;
 
-        id[i] = tem + 65;
+        id[i] = (uint8_t)(tem + 65);
     }
 
     memcpy(&uid.id, &id, UUID_LENGTH);
@@ -183,7 +183,7 @@ TEST (PDMDeleteDevice, ValidButNonExistDeviceID)
     {
         int tem = rand() % 25;
 
-        id[i] = tem + 65;
+        id[i] = (uint8_t)(tem + 65);
     }
 
     memcpy(&uid.id, &id, sizeof(uid.id));
index 045387d..b542fb7 100644 (file)
@@ -186,15 +186,15 @@ static FILE* TestFopen(const char *path, const char *mode)
     }
 }
 
-void SetPersistentHandler(OCPersistentStorage *ps)
+void SetPersistentHandler(OCPersistentStorage *persistentStorage)
 {
-    if(ps)
+    if(persistentStorage)
     {
-        ps->open = TestFopen;
-        ps->read = fread;
-        ps->write = fwrite;
-        ps->close = fclose;
-        ps->unlink = remove;
+        persistentStorage->open = TestFopen;
+        persistentStorage->read = fread;
+        persistentStorage->write = fwrite;
+        persistentStorage->close = fclose;
+        persistentStorage->unlink = remove;
     }
 }
 
@@ -418,9 +418,9 @@ TEST(SRPProvisionTrustCertChainTest, SRPProvisionTrustCertChainNullResultCallbac
     int ctx;
     OicSecCredType_t type = SIGNED_ASYMMETRIC_KEY;
     uint16_t credId = 0;
-    OCProvisionDev_t selectedDeviceInfo;
+    OCProvisionDev_t deviceInfo;
 
-    result = SRPProvisionTrustCertChain(&ctx, type, credId, &selectedDeviceInfo, NULL);
+    result = SRPProvisionTrustCertChain(&ctx, type, credId, &deviceInfo, NULL);
     EXPECT_EQ(OC_STACK_INVALID_CALLBACK, result);
 }
 
@@ -430,9 +430,9 @@ TEST(SRPProvisionTrustCertChainTest, SRPProvisionTrustCertChainInvalidOicSecCred
     int ctx;
     OicSecCredType_t type = PIN_PASSWORD;
     uint16_t credId = 0;
-    OCProvisionDev_t selectedDeviceInfo;
+    OCProvisionDev_t deviceInfo;
 
-    result = SRPProvisionTrustCertChain(&ctx, type, credId, &selectedDeviceInfo, provisioningCB);
+    result = SRPProvisionTrustCertChain(&ctx, type, credId, &deviceInfo, provisioningCB);
     EXPECT_EQ(OC_STACK_INVALID_PARAM, result);
 }
 
@@ -442,9 +442,9 @@ TEST_F(SRPTest, SRPProvisionTrustCertChainNoResource)
     int ctx;
     OicSecCredType_t type = SIGNED_ASYMMETRIC_KEY;
     uint16_t credId = 0;
-    OCProvisionDev_t selectedDeviceInfo;
+    OCProvisionDev_t deviceInfo;
 
-    result = SRPProvisionTrustCertChain(&ctx, type, credId, &selectedDeviceInfo, provisioningCB);
+    result = SRPProvisionTrustCertChain(&ctx, type, credId, &deviceInfo, provisioningCB);
     EXPECT_EQ(OC_STACK_NO_RESOURCE, result);
 }
 
index 5566e94..3ecb643 100644 (file)
@@ -137,7 +137,7 @@ TEST(ACLResourceTest, CBORDefaultACLConversion)
     OCStackResult convRet = AclToCBORPayload(defaultAcl, &defaultPsStorage, &defaultAclSize);
     EXPECT_EQ(OC_STACK_OK, convRet);
     ASSERT_TRUE(NULL != defaultPsStorage);
-    EXPECT_NE(0, defaultAclSize);
+    EXPECT_NE(static_cast<size_t>(0), defaultAclSize);
 
     OicSecAcl_t* convertedAcl = CBORPayloadToAcl(defaultPsStorage, defaultAclSize);
     ASSERT_TRUE(NULL != convertedAcl);
index 1aab21f..3ef3fea 100644 (file)
@@ -89,7 +89,7 @@ TEST(CRLResourceTest, GetDerCrl)
 {
     ByteArray crlArray = {NULL, 0};
     GetDerCrl(&crlArray);
-    EXPECT_NE(0, crlArray.len);
+    EXPECT_NE(static_cast<size_t>(0), crlArray.len);
 }
 
 #endif
index eea01e4..3c9555d 100644 (file)
@@ -81,7 +81,7 @@ bool ReadCBORFile(const char* filename, const char* rsrcname, uint8_t **payload,
     int ret = snprintf(filepath, len, "%s%s", STRINGIZE(SECURITY_BUILD_UNITTEST_DIR), filename);
     printf("Root build path: %s \n", filepath);
 
-    if (ret == (len - 1))
+    if (ret == (int)(len - 1))
     {
         FILE *fp = fopen(filepath, "rb");
         if (fp)
@@ -98,7 +98,7 @@ bool ReadCBORFile(const char* filename, const char* rsrcname, uint8_t **payload,
                     }
                     else
                     {
-                        size = st.st_size;
+                        size = (size_t)st.st_size;
 
                         CborValue cbor = {0, };
                         CborParser parser = {0, };
index 76632c8..f904504 100644 (file)
@@ -27,7 +27,7 @@ Import('test_env')
 security_test_env = test_env.Clone()
 
 if security_test_env.get('TARGET_OS') in ['windows', 'msys_nt']:
-    security_test_env.AppendUnique(CCFLAGS=['/W3', '/WX'])
+    security_test_env.AppendUnique(CCFLAGS=['/W4', '/WX'])
 
 SConscript('../unittest/SConscript', exports = { 'test_env' : security_test_env })
 SConscript('../provisioning/unittest/SConscript', exports = { 'test_env' : security_test_env })