Fixed shift-negative-value warning
authorGeorge Nash <george.nash@intel.com>
Wed, 7 Sep 2016 23:18:01 +0000 (16:18 -0700)
committerRick Bell <richard.s.bell@intel.com>
Fri, 9 Sep 2016 16:41:16 +0000 (16:41 +0000)
The compilar was interpreting the number zero '0' as a
signed number not an unsigned number. The left shift behavior
for signed numbers is undefined. The 'u' sufix was added to
tell the compilar that the '0' is an unsigned number.

Change-Id: Ida6c5c5ee2a7ea556755ca55d71858469a0691ac
Signed-off-by: George Nash <george.nash@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/11525
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Larry Sachs <larry.j.sachs@intel.com>
Reviewed-by: jaehyun Cho <jaehyun3.cho@samsung.com>
Reviewed-by: Rick Bell <richard.s.bell@intel.com>
resource/csdk/connectivity/src/adapter_util/cafragmentation.c

index 64af936..7870ad5 100644 (file)
@@ -56,12 +56,12 @@ static void CASetBits(uint8_t *x, unsigned p, unsigned n, unsigned v)
         OIC_LOG(ERROR, TAG, "set bits - lower err");
         return;
     }
-    else if(~(unsigned)(~0<<n) < v)
+    else if(~(unsigned)(~0u<<n) < v)
     {
         OIC_LOG(ERROR, TAG, "set bits - upper err");
         return;
     }
-    *x = (*x & (~(~0 << (p-n+1)))) | (*x & (~0 << (p+1))) | ((v & ~(~0 << n)) << (p-n+1));
+    *x = (*x & (~(~0u << (p-n+1)))) | (*x & (~0u << (p+1))) | ((v & ~(~0u << n)) << (p-n+1));
 }
 
 /**
@@ -76,7 +76,7 @@ static void CASetBits(uint8_t *x, unsigned p, unsigned n, unsigned v)
  */
 static uint8_t CAGetBits(uint8_t x, unsigned p, unsigned n)
 {
-    return (x >> (p + 1 - n)) & ~(~0 << n);
+    return (x >> (p + 1 - n)) & ~(~0u << n);
 }
 
 CAResult_t CAGenerateVariableForFragmentation(size_t dataLength,