X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdePkg%2FLibrary%2FBaseSafeIntLib%2FSafeIntLibEbc.c;fp=MdePkg%2FLibrary%2FBaseSafeIntLib%2FSafeIntLibEbc.c;h=93071cd9465d4b7162da2c98f4e80fa02e9619a1;hp=de28bec9770498b45015ea64210cbf19caf2cb7c;hb=2f88bd3a1296c522317f1c21377876de63de5be7;hpb=1436aea4d5707e672672a11bda72be2c63c936c3 diff --git a/MdePkg/Library/BaseSafeIntLib/SafeIntLibEbc.c b/MdePkg/Library/BaseSafeIntLib/SafeIntLibEbc.c index de28bec977..93071cd946 100644 --- a/MdePkg/Library/BaseSafeIntLib/SafeIntLibEbc.c +++ b/MdePkg/Library/BaseSafeIntLib/SafeIntLibEbc.c @@ -42,7 +42,8 @@ SafeInt32ToUintn ( if (sizeof (UINTN) == sizeof (UINT32)) { return SafeInt32ToUint32 (Operand, (UINT32 *)Result); } - return SafeInt32ToUint64 (Operand, (UINT64 *) Result); + + return SafeInt32ToUint64 (Operand, (UINT64 *)Result); } /** @@ -79,6 +80,7 @@ SafeUint32ToIntn ( if (sizeof (UINTN) == sizeof (UINT32)) { return SafeUint32ToInt32 (Operand, (INT32 *)Result); } + *Result = Operand; return RETURN_SUCCESS; } @@ -118,7 +120,8 @@ SafeIntnToInt32 ( *Result = (INT32)Operand; return RETURN_SUCCESS; } - return SafeInt64ToInt32 ((INT64) Operand, Result); + + return SafeInt64ToInt32 ((INT64)Operand, Result); } /** @@ -157,14 +160,15 @@ SafeIntnToUint32 ( if (sizeof (UINTN) == sizeof (UINT32)) { if (Operand >= 0) { *Result = (UINT32)Operand; - Status = RETURN_SUCCESS; + Status = RETURN_SUCCESS; } else { *Result = UINT32_ERROR; - Status = RETURN_BUFFER_TOO_SMALL; + Status = RETURN_BUFFER_TOO_SMALL; } return Status; } + return SafeInt64ToUint32 ((INT64)Operand, Result); } @@ -203,6 +207,7 @@ SafeUintnToUint32 ( *Result = (UINT32)Operand; return RETURN_SUCCESS; } + return SafeUint64ToUint32 ((UINT64)Operand, Result); } @@ -241,6 +246,7 @@ SafeUintnToInt64 ( *Result = (INT64)Operand; return RETURN_SUCCESS; } + return SafeUint64ToInt64 ((UINT64)Operand, Result); } @@ -278,6 +284,7 @@ SafeInt64ToIntn ( if (sizeof (UINTN) == sizeof (UINT32)) { return SafeInt64ToInt32 (Operand, (INT32 *)Result); } + *Result = (INTN)Operand; return RETURN_SUCCESS; } @@ -312,6 +319,7 @@ SafeInt64ToUintn ( if (sizeof (UINTN) == sizeof (UINT32)) { return SafeInt64ToUint32 (Operand, (UINT32 *)Result); } + return SafeInt64ToUint64 (Operand, (UINT64 *)Result); } @@ -347,8 +355,9 @@ SafeUint64ToUintn ( } if (sizeof (UINTN) == sizeof (UINT32)) { - return SafeUint64ToUint32 ((UINT64) Operand, (UINT32 *)Result); + return SafeUint64ToUint32 ((UINT64)Operand, (UINT32 *)Result); } + *Result = Operand; return RETURN_SUCCESS; } @@ -391,14 +400,15 @@ SafeUintnAdd ( if (sizeof (UINTN) == sizeof (UINT32)) { if ((UINT32)(Augend + Addend) >= Augend) { *Result = (Augend + Addend); - Status = RETURN_SUCCESS; + Status = RETURN_SUCCESS; } else { *Result = UINTN_ERROR; - Status = RETURN_BUFFER_TOO_SMALL; + Status = RETURN_BUFFER_TOO_SMALL; } return Status; } + return SafeUint64Add ((UINT64)Augend, (UINT64)Addend, (UINT64 *)Result); } @@ -440,14 +450,15 @@ SafeUintnSub ( if (sizeof (UINTN) == sizeof (UINT32)) { if (Minuend >= Subtrahend) { *Result = (Minuend - Subtrahend); - Status = RETURN_SUCCESS; + Status = RETURN_SUCCESS; } else { *Result = UINTN_ERROR; - Status = RETURN_BUFFER_TOO_SMALL; + Status = RETURN_BUFFER_TOO_SMALL; } return Status; } + return SafeUint64Sub ((UINT64)Minuend, (UINT64)Subtrahend, (UINT64 *)Result); } @@ -483,10 +494,11 @@ SafeUintnMult ( UINT64 IntermediateResult; if (sizeof (UINTN) == sizeof (UINT32)) { - IntermediateResult = ((UINT64) Multiplicand) *((UINT64) Multiplier); + IntermediateResult = ((UINT64)Multiplicand) *((UINT64)Multiplier); return SafeUint64ToUintn (IntermediateResult, Result); } + return SafeUint64Mult ((UINT64)Multiplicand, (UINT64)Multiplier, (UINT64 *)Result); } @@ -522,6 +534,7 @@ SafeIntnAdd ( if (sizeof (UINTN) == sizeof (UINT32)) { return SafeInt64ToIntn (((INT64)Augend) + ((INT64)Addend), Result); } + return SafeInt64Add ((INT64)Augend, (INT64)Addend, (INT64 *)Result); } @@ -557,6 +570,7 @@ SafeIntnSub ( if (sizeof (UINTN) == sizeof (UINT32)) { return SafeInt64ToIntn (((INT64)Minuend) - ((INT64)Subtrahend), Result); } + return SafeInt64Sub ((INT64)Minuend, (INT64)Subtrahend, (INT64 *)Result); } @@ -592,6 +606,6 @@ SafeIntnMult ( if (sizeof (UINTN) == sizeof (UINT32)) { return SafeInt64ToIntn (((INT64)Multiplicand) *((INT64)Multiplier), Result); } + return SafeInt64Mult ((INT64)Multiplicand, (INT64)Multiplier, (INT64 *)Result); } -