Fixed build warnings in stack
authorErich Keane <erich.keane@intel.com>
Tue, 17 Mar 2015 22:19:38 +0000 (15:19 -0700)
committerSashi Penta <sashi.kumar.penta@intel.com>
Tue, 24 Mar 2015 17:23:10 +0000 (17:23 +0000)
OCException's string handling was missing a few items.

ocstack used some creative casting to get a 16 bit value out
of an 8 bit array that could likely result in bad-optimizations
or undefined behavior.

Removed an unused variable.

Change-Id: I9af5d22f450f72d15b793cec57630e8c81f7b5de
Signed-off-by: Erich Keane <erich.keane@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/496
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Sachin Agrawal <sachin.agrawal@intel.com>
Reviewed-by: Sashi Penta <sashi.kumar.penta@intel.com>
resource/csdk/stack/src/occollection.c
resource/csdk/stack/src/ocstack.c
resource/include/StringConstants.h
resource/src/OCException.cpp

index 2156ee4..fd18359 100644 (file)
@@ -26,6 +26,8 @@
 #include "logger.h"
 #include "ocmalloc.h"
 #include "cJSON.h"
+#include "ocmalloc.h"
+
 /// Module Name
 #include <stdio.h>
 
index 7a2cee4..6e2427f 100644 (file)
@@ -121,7 +121,8 @@ static OCStackResult OCBuildIPv4Address(uint8_t a, uint8_t b, uint8_t c, uint8_t
     ipAddr->addr[1] = b;
     ipAddr->addr[2] = c;
     ipAddr->addr[3] = d;
-    *((uint16_t*)&(ipAddr->addr[4])) = port;
+    ipAddr->addr[4] = (uint8_t)port;
+    ipAddr->addr[5] = (uint8_t)(port >> 8);
 
     return OC_STACK_OK;
 }
@@ -3067,8 +3068,6 @@ OCStackResult initResources()
  */
 void insertResource(OCResource *resource)
 {
-    OCResource *pointer = NULL;
-
     if (!headResource) {
         headResource = resource;
         tailResource = resource;
@@ -3612,7 +3611,7 @@ int32_t OCDevAddrToPort(OCDevAddr *ipAddr, uint16_t *port)
         return OC_STACK_INVALID_PARAM;
     }
 
-    *port = *((uint16_t*)&ipAddr->addr[4]);
+    *port = (ipAddr->addr[5]<< 8) | ipAddr->addr[4];
 
     return OC_STACK_OK;
 }
index 355b6a7..4bb245b 100644 (file)
@@ -74,6 +74,8 @@ namespace OC
         static const char INVALID_OBESERVE[]           = "Invalid Observe Param";
         static const char NO_MEMORY[]                  = "No Memory";
         static const char COMM_ERROR[]                 = "Communication Error";
+        static const char TIMEOUT[]                    = "Timeout";
+        static const char ADAPTER_NOT_ENABLED[]        = "Adapter Not Enabled";
         static const char NOT_IMPL[]                   = "Not Implemented";
         static const char NOT_FOUND[]                  = "Resource Not Found";
         static const char RESOURCE_ERROR[]             = "Resource Error";
index 104ce42..64d1cfd 100644 (file)
@@ -51,6 +51,10 @@ std::string OC::OCException::reason(const OCStackResult sr)
             return OC::Exception::NO_MEMORY;
         case OC_STACK_COMM_ERROR:
             return OC::Exception::COMM_ERROR;
+        case OC_STACK_TIMEOUT:
+            return OC::Exception::TIMEOUT;
+        case OC_STACK_ADAPTER_NOT_ENABLED:
+            return OC::Exception::ADAPTER_NOT_ENABLED;
         case OC_STACK_NOTIMPL:
             return OC::Exception::NOT_IMPL;
         case OC_STACK_NO_RESOURCE: