[IOT-1911] Make resource/csdk/stack W4 compliant.
authorAlex Kelley <alexke@microsoft.com>
Thu, 9 Mar 2017 16:48:49 +0000 (08:48 -0800)
committerDave Thaler <dthaler@microsoft.com>
Tue, 14 Mar 2017 17:36:54 +0000 (17:36 +0000)
These changes include the following:
- Fix W4 warnings under resource/csdk/stack.
- Fix W4 warnings under resource/csdk/stack/test.
- Enable /W4 /WX on resource/csdk/stack.
- Enable /W4 /WX on resource/csdk/stack/test.
- Move disabling warnings from resource/csdk/security
  to build_common/Windows.

Change-Id: Ifed02e4e339093e49b6d174dfe3e3d52469f24ac
Signed-off-by: Alex Kelley <alexke@microsoft.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/17831
Reviewed-by: George Nash <george.nash@intel.com>
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: Dave Thaler <dthaler@microsoft.com>
15 files changed:
build_common/windows/SConscript
resource/c_common/platform_features.h
resource/csdk/connectivity/src/ip_adapter/arduino/caipclient_eth.cpp
resource/csdk/security/SConscript
resource/csdk/stack/SConscript
resource/csdk/stack/src/ocendpoint.c
resource/csdk/stack/src/ocpayload.c
resource/csdk/stack/src/ocpayloadconvert.c
resource/csdk/stack/src/ocpayloadparse.c
resource/csdk/stack/src/ocresource.c
resource/csdk/stack/src/ocstack.c
resource/csdk/stack/src/oicgroup.c
resource/csdk/stack/src/oicresourcedirectory.c
resource/csdk/stack/test/SConscript
resource/csdk/stack/test/stacktests.cpp

index e5dc9c3..d56618e 100644 (file)
@@ -16,11 +16,16 @@ if env['CC'] == 'cl':
     #    - It is an acceptable approach for variable size structs.
     #  - warning C4201: nameless struct/union
     #    - Disabled due to IoTivity not being ANSI compatible
+    #  - warning C4204: nonstandard extension used: non-constant aggregate initializer
+    #    - Disabled due to IoTivity not being ANSI compatible and this is an appropriate way to intialize
+    #      structs for non-legacy compilers.
     #  - warning C4214:  bit field types other than int
     #    - Disabled due to IoTivity not being ANSI compatible
+    #  - warning C4232: nonstandard extension used: 'read': address of dllimport 'fread' is not static, identity not guaranteed
+    #    - fread, frwrite, etc are provided by the platform and cannot be changed.
     #  - warning C4706: assignment within conditional expression
     #    - Disabled due to the widespread usage in IoTivity and low impact.
-    env.AppendUnique(CCFLAGS=['/wd4127', '/wd4200', '/wd4201', '/wd4214', '/wd4706'])
+    env.AppendUnique(CCFLAGS=['/wd4127', '/wd4200', '/wd4201', '/wd4204', '/wd4214', '/wd4232', '/wd4706'])
 
     env.AppendUnique(CCFLAGS=['/EHsc'])
 
index a419707..e674c82 100644 (file)
 #  define SIZE_MAX ((size_t)-1)
 #endif
 
+#ifdef WITH_ARDUINO
+/**
+ * UINT16_MAX does not appear to be defined on Arduino so we define it here.
+ */
+#  define UINT16_MAX 65535
+#endif
+
 #endif
index 5eb8d2b..45372e4 100644 (file)
@@ -59,10 +59,7 @@ libocsrm_env.PrependUnique(CPPPATH = [
 
 if target_os in ['windows', 'msys_nt']:
        libocsrm_env.AppendUnique(LIBPATH = [os.path.join(libocsrm_env.get('BUILD_DIR'), 'resource', 'oc_logger')])
-    # Enable W4 but disable the following warning:
-    #  - warning C4232: nonstandard extension used: 'read': address of dllimport 'fread' is not static, identity not guaranteed
-    #    - fread, frwrite, etc are provided by the platform and cannot be changed.
-       libocsrm_env.AppendUnique(CCFLAGS=['/wd4232', '/W4', '/WX'])
+       libocsrm_env.AppendUnique(CCFLAGS=['/W4', '/WX'])
 
 if target_os in ['linux', 'android', 'tizen', 'msys_nt', 'windows'] and libocsrm_env.get('SECURED') == '1':
        SConscript('provisioning/SConscript', 'libocsrm_env')
index 254f463..76527ed 100644 (file)
@@ -114,7 +114,7 @@ if target_os in ['android', 'linux', 'tizen', 'msys_nt', 'windows']:
 if target_os not in ['windows', 'msys_nt']:
     liboctbstack_env.AppendUnique(LIBS = ['m'])
 else:
-    liboctbstack_env.AppendUnique(CCFLAGS=['/W3', '/WX'])
+    liboctbstack_env.AppendUnique(CCFLAGS=['/W4', '/WX'])
     # octbstack.def specifies the list of functions exported by octbstack.dll.
     liboctbstack_env.Replace(WINDOWS_INSERT_DEF = ['1'])
 
index f4d248d..09357c1 100644 (file)
  *
  ******************************************************************/
 
- #include "ocendpoint.h"
- #include "logger.h"
- #include "oic_malloc.h"
- #include "oic_string.h"
- #include <string.h>
- #include "cainterface.h"
+#include "ocendpoint.h"
+#include "logger.h"
+#include "oic_malloc.h"
+#include "oic_string.h"
+#include <string.h>
+#include "cainterface.h"
 
 #define VERIFY_NON_NULL(arg) { if (!arg) {OIC_LOG(FATAL, TAG, #arg " is NULL"); goto exit;} }
 #define VERIFY_GT_ZERO(arg) { if (arg < 1) {OIC_LOG(FATAL, TAG, #arg " < 1"); goto exit;} }
 #define VERIFY_GT(arg1, arg2) { if (arg1 <= arg2) {OIC_LOG(FATAL, TAG, #arg1 " <= " #arg2); goto exit;} }
+#define VERIFY_LT_OR_EQ(arg1, arg2) { if (arg1 > arg2) {OIC_LOG(FATAL, TAG, #arg1 " > " #arg2); goto exit;} }
 #define TAG  "OIC_RI_ENDPOINT"
 
 OCStackResult OCGetSupportedEndpointFlags(const OCTpsSchemeFlags givenFlags, OCTpsSchemeFlags* out)
@@ -400,12 +401,15 @@ OCStackResult OCParseEndpointString(const char* endpointStr, OCEndpointPayload*
 
         // port start pos
         tokPos = tmp + 1;
-        VERIFY_GT_ZERO(atoi(tokPos));
+        char* end = NULL;
+        long port = strtol(tokPos, &end, 10);
+        VERIFY_GT_ZERO(port);
+        VERIFY_LT_OR_EQ(port, UINT16_MAX);
         OIC_LOG_V(INFO, TAG, "parsed port is:%s", tokPos);
 
         out->tps = tps;
         out->addr = addr;
-        out->port = atoi(tokPos);
+        out->port = (uint16_t)port;
     }
 
     OICFree(origin);
index 2c8648e..6a934be 100644 (file)
@@ -825,7 +825,7 @@ bool OCRepPayloadGetPropPubDataType(const OCRepPayload *payload, const char *nam
         else
         {
             value->data = val.bytes;
-            value->len  = strlen(val.bytes);
+            value->len  = strlen((const char*)val.bytes);
         }
     }
     else
@@ -984,8 +984,8 @@ bool OCRepPayloadGetByteStringArray(const OCRepPayload* payload, const char* nam
         {
             for (size_t j = 0; j < i; ++j)
             {
-                OCByteString* tmp = &(*array)[j];
-                OICFree(tmp->bytes);
+                OCByteString* temp = &(*array)[j];
+                OICFree(temp->bytes);
             }
             OICFree(*array);
             *array = NULL;
index e360790..9132bf8 100755 (executable)
@@ -411,10 +411,10 @@ static int64_t OCConvertDiscoveryPayload(OCDiscoveryPayload *payload, uint8_t *o
                 err |= cbor_encoder_create_array(&linkMap, &epsArray, epsCount);
                 VERIFY_CBOR_SUCCESS(TAG, err, "Failed setting endpoints array");
 
-                for (size_t i = 0; i < epsCount; ++i)
+                for (size_t j = 0; j < epsCount; ++j)
                 {
                     CborEncoder endpointMap;
-                    OCEndpointPayload* endpoint = OCEndpointPayloadGetEndpoint(resource->eps, i);
+                    OCEndpointPayload* endpoint = OCEndpointPayloadGetEndpoint(resource->eps, j);
                     VERIFY_PARAM_NON_NULL(TAG, endpoint, "Failed retrieving endpoint");
 
                     char* endpointStr = OCCreateEndpointString(endpoint);
index 62a187d..281e576 100755 (executable)
@@ -375,7 +375,6 @@ static OCStackResult OCParseDiscoveryPayload(OCPayload **outPayload, CborValue *
                         endpoint = NULL;
                         int pri = 0;
                         char *endpointStr = NULL;
-                        OCStackResult ret = OC_STACK_ERROR;
                         endpoint = (OCEndpointPayload *)OICCalloc(1, sizeof(OCEndpointPayload));
                         VERIFY_PARAM_NON_NULL(TAG, endpoint, "Failed allocating endpoint payload");
 
@@ -385,10 +384,10 @@ static OCStackResult OCParseDiscoveryPayload(OCPayload **outPayload, CborValue *
                         err = cbor_value_dup_text_string(&curVal, &endpointStr, &len, NULL);
                         VERIFY_CBOR_SUCCESS(TAG, err, "to find endpoint value");
 
-                        ret = OCParseEndpointString(endpointStr, endpoint);
+                        OCStackResult parseResult = OCParseEndpointString(endpointStr, endpoint);
                         OICFree(endpointStr);
 
-                        if (OC_STACK_OK == ret)
+                        if (OC_STACK_OK == parseResult)
                         {
                             // pri
                             err = cbor_value_map_find_value(&epMap, OC_RSRVD_PRIORITY, &curVal);
@@ -401,7 +400,7 @@ static OCStackResult OCParseDiscoveryPayload(OCPayload **outPayload, CborValue *
                         }
                         else
                         {
-                            if (OC_STACK_ADAPTER_NOT_ENABLED == ret)
+                            if (OC_STACK_ADAPTER_NOT_ENABLED == parseResult)
                             {
                                 OIC_LOG(ERROR, TAG, "Ignore unrecognized endpoint info");
                             }
index ae86922..d4436ad 100755 (executable)
@@ -687,7 +687,7 @@ OCStackResult DevicePropertiesToCBORPayload(const OCDeviceProperties *deviceProp
     }
     else
     {
-        result = OC_STACK_NO_MEMORY;
+        return OC_STACK_NO_MEMORY;
     }
 
     // Protocol Independent ID - Mandatory
@@ -987,11 +987,10 @@ OCStackResult BuildIntrospectionPayloadResponse(const OCResource *resourcePtr,
 {
     OC_UNUSED(resourcePtr);
     OC_UNUSED(devAddr);
-    OCRepPayload *tempPayload = NULL;
-    OCStackResult ret;
+
     char *introspectionData = NULL;
     size_t size = 0;
-    ret = GetIntrospectionDataFromPS(&introspectionData, &size);
+    OCStackResult ret = GetIntrospectionDataFromPS(&introspectionData, &size);
     if (OC_STACK_OK == ret)
     {
         OCRepPayload *tempPayload = OCRepPayloadCreate();
@@ -1001,6 +1000,11 @@ OCStackResult BuildIntrospectionPayloadResponse(const OCResource *resourcePtr,
             {
                 *payload = tempPayload;
             }
+            else
+            {
+                OCRepPayloadDestroy(tempPayload);
+                ret = OC_STACK_ERROR;
+            }
         }
         else
         {
@@ -1010,7 +1014,6 @@ OCStackResult BuildIntrospectionPayloadResponse(const OCResource *resourcePtr,
     if (ret != OC_STACK_OK)
     {
         OICFree(introspectionData);
-        OCRepPayloadDestroy(tempPayload);
     }
 
     return ret;
@@ -1117,6 +1120,7 @@ OCStackResult BuildIntrospectionResponseRepresentation(const OCResource *resourc
     OCRepPayload** payload, OCDevAddr *devAddr)
 {
     OC_UNUSED(devAddr);
+
     size_t dimensions[3] = { 0, 0, 0 };
     OCRepPayload *tempPayload = NULL;
     OCRepPayload **urlInfoPayload = NULL;
@@ -1838,9 +1842,6 @@ static OCStackResult HandleVirtualResource (OCServerRequest *request, OCResource
             goto exit;
         }
 
-        char *interfaceQuery = NULL;
-        char *resourceTypeQuery = NULL;
-
         CAEndpoint_t *networkInfo = NULL;
         size_t infoSize = 0;
 
index cbba02f..8993ef1 100644 (file)
@@ -1739,7 +1739,7 @@ void OCHandleResponse(const CAEndpoint_t* endPoint, const CAResponseInfo_t* resp
                     return;
                 }
 
-                for (uint8_t i = start; i < responseInfo->info.numOptions; i++)
+                for (int i = start; i < responseInfo->info.numOptions; i++)
                 {
                     memcpy (&(response->rcvdVendorSpecificHeaderOptions[i-start]),
                             &(responseInfo->info.options[i]), sizeof(OCHeaderOption));
index 0f133a5..881f838 100755 (executable)
@@ -936,14 +936,16 @@ OCPayload* BuildActionCBOR(OCAction* action)
     return (OCPayload*) payload;
 }
 
-unsigned int GetNumOfTargetResource(OCAction *actionset)
+uint8_t GetNumOfTargetResource(OCAction *actionset)
 {
-    int numOfResource = 0;
+    uint8_t numOfResource = 0;
 
     OCAction *pointerAction = actionset;
 
     while (pointerAction != NULL)
     {
+        assert(numOfResource < UINT8_MAX);
+
         numOfResource++;
         pointerAction = pointerAction->next;
     }
@@ -1244,11 +1246,13 @@ OCStackResult BuildCollectionGroupActionCBORResponse(
                     {
                         OIC_LOG_V(INFO, TAG, "Execute ActionSet : %s",
                                 actionset->actionsetName);
-                        unsigned int num = GetNumOfTargetResource(
-                                actionset->head);
+                        uint8_t num = GetNumOfTargetResource(actionset->head);
 
                         ((OCServerRequest *) ehRequest->requestHandle)->ehResponseHandler =
                                 HandleAggregateResponse;
+
+                        assert(num < UINT8_MAX);
+
                         ((OCServerRequest *) ehRequest->requestHandle)->numResponses =
                                 num + 1;
 
@@ -1324,12 +1328,12 @@ OCStackResult BuildCollectionGroupActionCBORResponse(
         else if (strcmp(doWhat, GET_ACTIONSET) == 0)
         {
             char *plainText = NULL;
-            OCActionSet *actionset = NULL;
+            OCActionSet *tempActionSet = NULL;
 
-            GetActionSet(details, resource->actionsetHead, &actionset);
-            if (actionset != NULL)
+            GetActionSet(details, resource->actionsetHead, &tempActionSet);
+            if (tempActionSet != NULL)
             {
-                BuildStringFromActionSet(actionset, &plainText);
+                BuildStringFromActionSet(tempActionSet, &plainText);
 
                 if (plainText != NULL)
                 {
index 01dfe86..80a002b 100644 (file)
@@ -187,8 +187,8 @@ static OCStackResult ResourcePayloadCreate(sqlite3_stmt *stmt, OCDiscoveryPayloa
         VERIFY_SQLITE(sqlite3_bind_int64(stmtIF, sqlite3_bind_parameter_index(stmtIF, "@id"), id));
         while (SQLITE_ROW == sqlite3_step(stmtIF))
         {
-            const unsigned char *itf = sqlite3_column_text(stmtIF, if_value_index);
-            result = appendStringLL(&resourcePayload->interfaces, itf);
+            const unsigned char *tempItf = sqlite3_column_text(stmtIF, if_value_index);
+            result = appendStringLL(&resourcePayload->interfaces, tempItf);
             if (OC_STACK_OK != result)
             {
                 goto exit;
@@ -215,9 +215,9 @@ static OCStackResult ResourcePayloadCreate(sqlite3_stmt *stmt, OCDiscoveryPayloa
         if (SQLITE_ROW == res || SQLITE_DONE == res)
         {
             const unsigned char *di = sqlite3_column_text(stmt1, di_index);
-            const unsigned char *address = sqlite3_column_text(stmt1, address_index);
-            OIC_LOG_V(DEBUG, TAG, " %s %s", di, address);
-            discPayload->baseURI = OICStrdup((char *)address);
+            const unsigned char *tempAddress = sqlite3_column_text(stmt1, address_index);
+            OIC_LOG_V(DEBUG, TAG, " %s %s", di, tempAddress);
+            discPayload->baseURI = OICStrdup((char *)tempAddress);
             if (!discPayload->baseURI)
             {
                 result = OC_STACK_NO_MEMORY;
index 902a8c6..c87eade 100644 (file)
@@ -62,7 +62,7 @@ if stacktest_env.get('LOGGING'):
 
 if target_os in ['msys_nt', 'windows']:
     stacktest_env.PrependUnique(LIBS = ['sqlite3'])
-    stacktest_env.AppendUnique(CCFLAGS=['/W3', '/WX'])
+    stacktest_env.AppendUnique(CCFLAGS=['/W4', '/WX'])
 else:
     stacktest_env.PrependUnique(LIBS = ['m'])
 
index a5e024d..b2cf0b3 100644 (file)
@@ -2708,5 +2708,5 @@ TEST(StackZoneId, getZoneIdWithInvalidParams)
     char *zoneId = NULL;
     EXPECT_EQ(OC_STACK_INVALID_PARAM, OCGetLinkLocalZoneId(0, NULL));
     EXPECT_EQ(OC_STACK_ERROR, OCGetLinkLocalZoneId(9999, &zoneId));
-    EXPECT_EQ(OC_STACK_ERROR, OCGetLinkLocalZoneId(-1, &zoneId));
+    EXPECT_EQ(OC_STACK_ERROR, OCGetLinkLocalZoneId(UINT32_MAX, &zoneId));
 }