]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/BaseSafeIntLib/SafeIntLib.c
MdePkg/BaseSafeIntLib: Fix VS2015 IA32 NOOPT build failure
[mirror_edk2.git] / MdePkg / Library / BaseSafeIntLib / SafeIntLib.c
index 56d97cf65601835aacd0d1e79cf2318368f3e9cf..e96327d1347ba1efefe0eda76e88874d465719c3 100644 (file)
 \r
 #include <Base.h>\r
 #include <Library/SafeIntLib.h>\r
+#include <Library/BaseLib.h>\r
 \r
 \r
 //\r
 // Magnitude of MIN_INT64 as expressed by a UINT64 number.\r
 //\r
-#define MIN_INT64_MAGNITUDE ((((UINT64) - (MIN_INT64 + 1))) + 1)\r
+#define MIN_INT64_MAGNITUDE (((UINT64)(- (MIN_INT64 + 1))) + 1)\r
 \r
 //\r
 // Conversion functions\r
@@ -3373,8 +3374,8 @@ SafeUint64Mult (
   // b * c must be less than 2^32 or there would be bits in the high 64-bits\r
   // then there must be no overflow of the resulting values summed up.\r
   //\r
-  DwordA = (UINT32)(Multiplicand >> 32);\r
-  DwordC = (UINT32)(Multiplier >> 32);\r
+  DwordA = (UINT32)RShiftU64 (Multiplicand, 32);\r
+  DwordC = (UINT32)RShiftU64 (Multiplier, 32);\r
 \r
   //\r
   // common case -- if high dwords are both zero, no chance for overflow\r
@@ -3409,7 +3410,7 @@ SafeUint64Mult (
           // now sum them all up checking for overflow.\r
           // shifting is safe because we already checked for overflow above\r
           //\r
-          if (!RETURN_ERROR (SafeUint64Add (ProductBC << 32, ProductAD << 32, &UnsignedResult))) {\r
+          if (!RETURN_ERROR (SafeUint64Add (LShiftU64 (ProductBC, 32), LShiftU64 (ProductAD, 32), &UnsignedResult))) {\r
             //\r
             // b * d\r
             //\r
@@ -4075,7 +4076,7 @@ SafeInt32Mult (
   OUT INT32  *Result\r
   )\r
 {\r
-  return SafeInt64ToInt32 (((INT64)Multiplicand) *((INT64)Multiplier), Result);\r
+  return SafeInt64ToInt32 (MultS64x64 (Multiplicand, Multiplier), Result);\r
 }\r
 \r
 /**\r
@@ -4143,6 +4144,8 @@ SafeInt64Mult (
       if (UnsignedResult > MIN_INT64_MAGNITUDE) {\r
         *Result = INT64_ERROR;\r
         Status = RETURN_BUFFER_TOO_SMALL;\r
+      } else if (UnsignedResult == MIN_INT64_MAGNITUDE) {\r
+        *Result = MIN_INT64;\r
       } else {\r
         *Result = - ((INT64)UnsignedResult);\r
       }\r