Fix shift-negative-value warning
authorKalle Raita <kraita@google.com>
Thu, 10 Dec 2015 21:25:25 +0000 (13:25 -0800)
committerKalle Raita <kraita@google.com>
Thu, 10 Dec 2015 21:25:25 +0000 (13:25 -0800)
Change-Id: I4709933cc873ed34d3f67b2a258f542d56018428

framework/delibs/debase/deInt32.h
framework/delibs/debase/deInt32Test.c

index c1b488755e0e97ef11055978f795c91dc5397bdf..4806fe6b9599d485dc37907347dfe47fa07ccb91 100644 (file)
@@ -519,7 +519,7 @@ DE_INLINE deInt32 deInt32ModF (deInt32 n, deInt32 d)
 
 DE_INLINE deBool deInt64InInt32Range (deInt64 x)
 {
-       return ((x >= (-1ll<<31)) && (x <= ((1ll<<31)-1)));
+       return ((x >= (((deInt64)((deInt32)(-0x7FFFFFFF - 1))))) && (x <= ((1ll<<31)-1)));
 }
 
 
index d87aee7f5d728e92c001eb1bead8c25eb2be48fb..a79d08e63b090be6ba5dfdbb2d2f5ddf67783180 100644 (file)
@@ -198,6 +198,20 @@ void deInt32_selfTest (void)
        DE_TEST_ASSERT(deReverseBytes32(0xfecddeef) == 0xefdecdfe);
        DE_TEST_ASSERT(deReverseBytes16(0x1122) == 0x2211);
        DE_TEST_ASSERT(deReverseBytes16(0xdeef) == 0xefde);
+
+       DE_TEST_ASSERT(deInt64InInt32Range((deInt64)0x7FFFFFF));
+       DE_TEST_ASSERT(deInt64InInt32Range(0));
+       DE_TEST_ASSERT(deInt64InInt32Range(1));
+       DE_TEST_ASSERT(deInt64InInt32Range(-1));
+       DE_TEST_ASSERT(deInt64InInt32Range(-((deInt64)0x7FFFFFF)));
+       DE_TEST_ASSERT(deInt64InInt32Range(-((deInt64)0x8000 << 16)));
+       DE_TEST_ASSERT(deInt64InInt32Range((deInt64)deIntMinValue32(32)));
+
+       DE_TEST_ASSERT(!deInt64InInt32Range((((deInt64)0x7FFFFFF) << 32) | (deInt64)0xFFFFFFFF));
+       DE_TEST_ASSERT(!deInt64InInt32Range((deInt64)0x7FFFFFFF + 1));
+       DE_TEST_ASSERT(!deInt64InInt32Range(-((deInt64)0x7FFFFFFF + 2)));
+       DE_TEST_ASSERT(!deInt64InInt32Range(-((((deInt64)0x7FFFFFF) << 32) | (deInt64)0xFFFFFFFF)));
+       DE_TEST_ASSERT(!deInt64InInt32Range((deInt64)deIntMinValue32(32) - 1));
 }
 
 DE_END_EXTERN_C