IOT-1583: Fixing /W3 warnings in /resource directory - part 1.
authorPawel Winogrodzki <pawelwi@microsoft.com>
Tue, 2 May 2017 07:41:38 +0000 (00:41 -0700)
committerDan Mihai <Daniel.Mihai@microsoft.com>
Sat, 6 May 2017 16:38:23 +0000 (16:38 +0000)
Fixing all /W4s inside the IPCA directory and a few minor
once inside service/.

Change-Id: I4054c9dff35ac415e0866652ba7fb9c39720f213
Signed-off-by: Pawel Winogrodzki <pawelwi@microsoft.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/19555
Reviewed-by: Omar Maabreh <omarm@microsoft.com>
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: Dan Mihai <Daniel.Mihai@microsoft.com>
19 files changed:
resource/IPCA/samples/ElevatorClient/ElevatorClient.cpp
resource/IPCA/samples/ElevatorClient/OCFDevice.cpp
resource/IPCA/samples/ElevatorServer/elevatorserver.cpp
resource/IPCA/samples/ipcaapp/ipcaapp.cpp
resource/IPCA/src/app.cpp
resource/IPCA/src/callback.cpp
resource/IPCA/src/common.cpp
resource/IPCA/src/inc/app.h
resource/IPCA/src/inc/callback.h
resource/IPCA/src/inc/ipcainternal.h
resource/IPCA/src/inc/ocfframework.h
resource/IPCA/src/ipcavariant.cpp
resource/IPCA/src/ocfframework.cpp
resource/IPCA/unittests/IPCAElevatorClient.cpp
resource/IPCA/unittests/mockOC.cpp
service/coap-http-proxy/src/CoapHttpHandler.c
service/coap-http-proxy/unittests/CoAPHttpUnitTest.cpp
service/notification/src/provider/NSProviderNotification.c
service/notification/src/provider/NSProviderTopic.c

index 0506879..c26c77d 100644 (file)
@@ -225,7 +225,7 @@ void DiscoverDevicesCallback(void* context,
     std::string deviceId = deviceInfo->deviceId;
     std::string deviceName = deviceInfo->deviceName;
     std::vector<std::string> deviceUris;
-    for (int i = 0; i < deviceInfo->deviceUriCount; i++)
+    for (size_t i = 0; i < deviceInfo->deviceUriCount; i++)
     {
         deviceUris.push_back(deviceInfo->deviceUris[i]);
     }
index 3f30edc..fa42b6a 100644 (file)
@@ -129,8 +129,7 @@ ResourceList OCFDevice::GetResourceInfo()
     }
 
     m_resourceList.clear();
-    size_t i;
-    for (i = 0 ; i < resourceListCount ; i++)
+    for (size_t i = 0 ; i < resourceListCount ; i++)
     {
         char** resourceTypes;
         size_t resourceTypeCount;
@@ -138,8 +137,7 @@ ResourceList OCFDevice::GetResourceInfo()
                     resourcePathList[i], &resourceTypes, &resourceTypeCount);
         if (IPCA_OK == status)
         {
-            int j;
-            for (j = 0 ; j < resourceTypeCount; j++)
+            for (size_t j = 0 ; j < resourceTypeCount; j++)
             {
                 m_resourceList[resourcePathList[i]].push_back(resourceTypes[j]);
             }
index 76e49c1..8ecbb88 100644 (file)
@@ -424,7 +424,7 @@ void ElevatorServer::NotifyObservers()
 
     OCRepresentation rep;
     rep["x.org.iotivity.CurrentFloor"] = GetCurrentFloor();
-    rep["x.org.iotivity.Direction"] = GetElevatorDirection();
+    rep["x.org.iotivity.Direction"] = (int)GetElevatorDirection();
     rep["x.org.iotivity.TargetFloor"] = GetTargetFloor();
 
     // Prepare the response.
index b850915..03448ce 100644 (file)
@@ -195,7 +195,7 @@ void OCFDevice::GetPropertiesCallback(IPCAStatus result,
     }
 
     std::map<std::string, IPCAValueType> properties;
-    for (int i = 0 ; i < count ; i++)
+    for (size_t i = 0 ; i < count ; i++)
     {
         properties[allKeys[i]] = allValueTypes[i];
     }
index 016816d..cd0600e 100644 (file)
@@ -145,7 +145,7 @@ void App::AppWorkerThread(App* app)
         uint64_t currentTime = OICGetCurrentTime(TIME_IN_MS);
 
         // Do periodic discovery for active IPCADiscoverDevices() requests.
-        std::map<uint32_t, std::vector<std::string>> resourceTypesToDiscover;
+        std::map<size_t, std::vector<std::string>> resourceTypesToDiscover;
         {
             std::lock_guard<std::mutex> lock(app->m_appMutex);
             for (auto& entry : app->m_discoveryList)
index 0363924..3d42d62 100644 (file)
@@ -280,10 +280,10 @@ IPCAStatus Callback::AddCallbackInfo(CallbackInfo::Ptr cbInfo)
     uint32_t i = 0;
     while (i++ < UINT_MAX)
     {
-        uint32_t newKey = m_nextKey++;
+        size_t newKey = m_nextKey++;
         if (m_callbackInfoList.find(newKey) == m_callbackInfoList.end())
         {
-            OIC_LOG_V(INFO, TAG, "AddCallbackInfo() with key: %d", newKey);
+            OIC_LOG_V(INFO, TAG, "AddCallbackInfo() with key: %" PRIuPTR, newKey);
             cbInfo->mapKey = newKey;
             m_callbackInfoList[newKey] = cbInfo;
             return IPCA_OK;
index a011f56..e9aef53 100644 (file)
@@ -145,7 +145,7 @@ void FreeArrayOfCharPointers(char** array, size_t count)
         return;
     }
 
-    for (int i = 0; i < count; i++)
+    for (size_t i = 0; i < count; i++)
     {
         OICFree((void*)(array[i]));
     }
index 6222e0d..0307f3d 100644 (file)
@@ -178,7 +178,7 @@ class App
 
         // List of resource types to discover periodically.
         // Key is cbInfo->mapKey of each IPCADiscoverDevices() request.
-        std::map<uint32_t, DiscoveryDetails::Ptr> m_discoveryList;
+        std::map<size_t, DiscoveryDetails::Ptr> m_discoveryList;
 
         // Password callback registration
         InputPinCallbackHandle m_passwordInputCallbackHandle;
index a3787c6..904b68a 100644 (file)
@@ -215,8 +215,8 @@ class Callback
         std::mutex m_discoverDeviceCallbackMutex;
 
         // Table of CallbackInfo.  Key is autogenerated.
-        std::atomic<uint32_t> m_nextKey;  // next key for the m_callbackInfoList map.
-        std::map<uint32_t, CallbackInfo::Ptr> m_callbackInfoList;  // List of expected callbacks.
+        std::atomic<size_t> m_nextKey;  // next key for the m_callbackInfoList map.
+        std::map<size_t, CallbackInfo::Ptr> m_callbackInfoList;  // List of expected callbacks.
         App* m_app; // Callback object is per app.
         volatile bool m_stopCalled;    // Set to true when Stop() is called.
 
index dc4fe68..7158e62 100644 (file)
@@ -30,7 +30,6 @@
 #include <condition_variable>
 
 #include <stdbool.h>
-#include <inttypes.h>
 #include <assert.h>
 #include <stdint.h>
 
index 1da1d21..c910cda 100644 (file)
@@ -209,7 +209,7 @@ class OCFFramework
 
         // Callback from OCF for MOT completion
         void OnMultipleOwnershipTransferCompleteCallback(PMResultList_t* result,
-                    bool error,
+                    int error,
                     std::string deviceId,
                     CallbackInfo::Ptr callbackInfo);
 
index bf1936a..f61281a 100644 (file)
@@ -406,7 +406,7 @@ IPCAStatus IPCAPropertyBagGetValuePropertyBagArray(IPCAPropertyBagHandle propert
     // rollback if any failure.
     if (i != ocrepCount)
     {
-        for (int x = 0; x < i; x++)
+        for (size_t x = 0; x < i; x++)
         {
             IPCAPropertyBagDestroy(*value[x]);
         }
index 1f2eee7..d908969 100644 (file)
@@ -240,7 +240,6 @@ IPCAStatus OCFFramework::Start(const IPCAAppInfoInternal& appInfo, bool isUnitTe
     OCDeviceInfo deviceInfo = { deviceName, &types, deviceSoftwareVersion, nullptr };
 
     // Platform Info
-    IPCAUuid platformUUID;
     char platformManufacturerName[256] = "";
     char manufacturerUrl[256] = "";
     char modelNumber[] = "";
@@ -1820,7 +1819,7 @@ void OCFFramework::RequestAccessWorkerThread(RequestAccessContext* requestContex
 
 void OCFFramework::OnMultipleOwnershipTransferCompleteCallback(
                                     PMResultList_t* result,
-                                    bool error,
+                                    int error,
                                     std::string deviceId,
                                     CallbackInfo::Ptr callbackInfo)
 {
index c833497..44e1b3e 100644 (file)
@@ -464,10 +464,9 @@ IPCAStatus IPCAElevatorClient::ConfirmResources()
     size_t resourcePathCount;
     EXPECT_EQ(IPCA_OK, IPCAGetResources(m_deviceHandle,
                             nullptr, nullptr, &resourcePathList, &resourcePathCount));
-    EXPECT_LT(0, resourcePathCount); // At least there must be elevator resource.
-    int i = 0;
+    EXPECT_LT(0U, resourcePathCount); // At least there must be elevator resource.
     bool elevatorResourceFound = false;
-    for (i = 0; i < resourcePathCount; i++)
+    for (size_t i = 0; i < resourcePathCount; i++)
     {
         std::string resourcePath = resourcePathList[i];
         if (resourcePath.find(ELEVATOR_KEYWORD) != std::string::npos)
@@ -488,10 +487,9 @@ IPCAStatus IPCAElevatorClient::ConfirmResourceTypes()
     size_t resourceTypeCount;
     EXPECT_EQ(IPCA_OK, IPCAGetResourceTypes(m_deviceHandle,
                             nullptr, &resourceTypes, &resourceTypeCount));
-    EXPECT_LT(0, resourceTypeCount);  // At least 1 resource type.
-    int i = 0;
+    EXPECT_LT(0U, resourceTypeCount);  // At least 1 resource type.
     bool elevatorResourceTypeFound = false;
-    for (i = 0; i < resourceTypeCount; i++)
+    for (size_t i = 0; i < resourceTypeCount; i++)
     {
         std::string rt = resourceTypes[i];
         if (rt.find(ELEVATOR_KEYWORD) != std::string::npos)
@@ -506,14 +504,14 @@ IPCAStatus IPCAElevatorClient::ConfirmResourceTypes()
     // Function list for a given resource.
     EXPECT_EQ(IPCA_RESOURCE_NOT_FOUND, IPCAGetResourceTypes(m_deviceHandle,
                                                 "oic/fake", &resourceTypes, &resourceTypeCount));
-    EXPECT_EQ(0, resourceTypeCount);
+    EXPECT_EQ(0U, resourceTypeCount);
     EXPECT_EQ(nullptr, resourceTypes);
 
     EXPECT_EQ(IPCA_OK, IPCAGetResourceTypes(m_deviceHandle,
                                     ELEVATOR_RESOURCE_PATH, &resourceTypes, &resourceTypeCount));
-    EXPECT_LT(0, resourceTypeCount);  // At least 1 function.
+    EXPECT_LT(0U, resourceTypeCount);  // At least 1 function.
     elevatorResourceTypeFound = false;
-    for (i = 0; i < resourceTypeCount; i++)
+    for (size_t i = 0; i < resourceTypeCount; i++)
     {
         std::string rt = resourceTypes[i];
         if (rt.find(ELEVATOR_KEYWORD) != std::string::npos)
@@ -535,7 +533,7 @@ IPCAStatus IPCAElevatorClient::ConfirmResourceInterfaces()
     size_t resourceInterfaceCount;
     EXPECT_EQ(IPCA_OK, IPCAGetResourceInterfaces(m_deviceHandle,
                             nullptr, &resourceInterfaces, &resourceInterfaceCount));
-    EXPECT_LT(1, resourceInterfaceCount);
+    EXPECT_LT(1U, resourceInterfaceCount);
 
     // Should return only 1 resource with ELEVATOR_CO_PRIVATE_INTERFACE interface.
     char** resourcePathList;
@@ -555,7 +553,7 @@ IPCAStatus IPCAElevatorClient::ConfirmResourceInterfaces()
                             nullptr,
                             &resourcePathList,
                             &resourcePathCount));
-    EXPECT_EQ(0, resourcePathCount);
+    EXPECT_EQ(0U, resourcePathCount);
     IPCAFreeStringArray(resourcePathList, resourcePathCount);
 
     // Should be at least 4 resouces with DEFAULT_INTERFACE created in ElevatorServer::Start().
@@ -564,7 +562,7 @@ IPCAStatus IPCAElevatorClient::ConfirmResourceInterfaces()
                             nullptr,
                             &resourcePathList,
                             &resourcePathCount));
-    EXPECT_LT(3, resourcePathCount);
+    EXPECT_LT(3U, resourcePathCount);
     IPCAFreeStringArray(resourcePathList, resourcePathCount);
 
     return IPCA_OK;
@@ -581,7 +579,7 @@ void IPCAElevatorClient::DiscoverElevator1Callback(
     if (g_elevator1Name.compare(discoveredDeviceInfo->deviceName) == 0)
     {
         m_discoveredElevator1DeviceUris.clear();
-        for (int i = 0; i < discoveredDeviceInfo->deviceUriCount; i++)
+        for (size_t i = 0; i < discoveredDeviceInfo->deviceUriCount; i++)
         {
             m_discoveredElevator1DeviceUris.push_back(discoveredDeviceInfo->deviceUris[i]);
         }
index a286937..048b4e2 100644 (file)
@@ -846,13 +846,13 @@ OCEntityHandlerResult MockEntityHandler(OCEntityHandlerFlag flag,
         std::lock_guard<std::recursive_mutex> lock(g_globalMutex);\r
         for (auto request : g_requestList)\r
         {\r
-            PendingRequest::Ptr pendingRequest = request.second;\r
-            if (pendingRequest->method & (OC_REST_OBSERVE | OC_REST_OBSERVE_ALL))\r
+            PendingRequest::Ptr localPendingRequest = request.second;\r
+            if (localPendingRequest->method & (OC_REST_OBSERVE | OC_REST_OBSERVE_ALL))\r
             {\r
-                if (pendingRequest->mockOCResource->m_uri.compare(uri) == 0)\r
+                if (localPendingRequest->mockOCResource->m_uri.compare(uri) == 0)\r
                 {\r
-                    observationIdToCancel = pendingRequest->observationId;\r
-                    g_requestList.erase(pendingRequest->requestNumber);\r
+                    observationIdToCancel = localPendingRequest->observationId;\r
+                    g_requestList.erase(localPendingRequest->requestNumber);\r
                     break;\r
                 }\r
             }\r
index 12f9ec1..56921f0 100644 (file)
@@ -153,17 +153,17 @@ static void CHPGetProxyURI(OCHeaderOption* options, uint8_t *numOptions, char* u
         return;
     }
 
-    for (int count = 0; count < *numOptions; count++)
+    for (uint8_t count = 0; count < *numOptions; count++)
     {
         if (options[count].protocolID == OC_COAP_ID &&
-                options[count].optionID == COAP_OPTION_PROXY_URI)
+            options[count].optionID == COAP_OPTION_PROXY_URI)
         {
             OIC_LOG(DEBUG, TAG, "Proxy URI is present");
             // Extract proxy-uri and delete it from headeroptions.
             OICStrcpy(uri, uriLength, (char *)options[count].optionData);
-            for (int fwd = count; fwd < *numOptions-1; fwd++)
+            for (uint8_t fwd = count; fwd < *numOptions - 1; fwd++)
             {
-                options[count] = options[count+1];
+                options[count] = options[count + 1];
             }
             *numOptions -= 1;
             return;
@@ -421,11 +421,11 @@ OCStackResult CHPHandleOCFRequest(const OCEntityHandlerRequest* requestInfo,
         return OC_STACK_ERROR;
     }
 
-    uint8_t vendorOptions = requestInfo->numRcvdVendorSpecificHeaderOptions;
-    if (vendorOptions)
+    uint8_t vendorOptionsCount = requestInfo->numRcvdVendorSpecificHeaderOptions;
+    if (vendorOptionsCount)
     {
         httpRequest.headerOptions = u_arraylist_create();
-        for (int option = 0; option < vendorOptions; option++)
+        for (uint8_t option = 0; option < vendorOptionsCount; option++)
         {
             HttpHeaderOption_t *httpOption = NULL;
             result = CHPGetHttpOption(requestInfo->rcvdVendorSpecificHeaderOptions + option,
index 31662b3..0c36e41 100644 (file)
@@ -91,7 +91,6 @@ TEST_F(CoApHttpTest, CHPGetOCCode)
 
 TEST_F(CoApHttpTest, CHPGetOCOption)
 {
-    int numOptions = 0;
     OCHeaderOption *ret = NULL;
     const HttpResponse_t *httpResponse = NULL;
     HttpHeaderOption_t *httpOption = NULL;
index eee46bc..3698e71 100644 (file)
@@ -109,7 +109,7 @@ NSResult NSSendNotification(NSMessage *msg)
 
     OCResourceHandle rHandle;
     OCObservationId obArray[255] = { 0, };
-    int obCount = 0, i;
+    size_t obCount = 0;
 
     if (NSPutMessageResource(msg, &rHandle) != NS_OK)
     {
@@ -172,10 +172,10 @@ NSResult NSSendNotification(NSMessage *msg)
         it = it->next;
     }
 
-    for (i = 0; i < obCount; ++i)
+    for (size_t i = 0; i < obCount; ++i)
     {
         NS_LOG(DEBUG, "-------------------------------------------------------message\n");
-        NS_LOG_V(DEBUG, "SubScription WhiteList[%d] = %d", i, obArray[i]);
+        NS_LOG_V(DEBUG, "SubScription WhiteList[%" PRIuPTR "] = %d", i, obArray[i]);
         NS_LOG(DEBUG, "-------------------------------------------------------message\n");
     }
 
@@ -212,8 +212,7 @@ NSResult NSSendSync(NSSyncInfo *sync)
     NS_LOG(DEBUG, "NSSendSync - IN");
 
     OCObservationId obArray[255] = { 0, };
-    int obCount = 0;
-    int i;
+    size_t obCount = 0;
 
     OCResourceHandle rHandle;
     if (NSPutSyncResource(sync, &rHandle) != NS_OK)
@@ -269,10 +268,10 @@ NSResult NSSendSync(NSSyncInfo *sync)
     }
 #endif
 
-    for (i = 0; i < obCount; ++i)
+    for (size_t i = 0; i < obCount; ++i)
     {
         NS_LOG(DEBUG, "-------------------------------------------------------message\n");
-        NS_LOG_V(DEBUG, "Sync WhiteList[%d] = %d", i, obArray[i]);
+        NS_LOG_V(DEBUG, "Sync WhiteList[%" PRIuPTR "] = %d", i, obArray[i]);
         NS_LOG(DEBUG, "-------------------------------------------------------message\n");
     }
 
index ca95960..c3d0797 100644 (file)
@@ -143,7 +143,7 @@ NSResult NSSendTopicUpdation()
 
     OCObservationId obArray[255] =
     { 0, };
-    int obCount = 0;
+    size_t obCount = 0;
 
     NSCacheElement * it = consumerSubList->head;