/** UINTN addition Performs the requested operation using the input parameters into a value specified by Result type and stores the converted value into the caller allocated output buffer specified by Result. The caller must pass in a Result buffer that is at least as large as the Result type. If Result is NULL, RETURN_INVALID_PARAMETER is returned. If the requested operation results in an overflow or an underflow condition, then Result is set to UINTN_ERROR and RETURN_BUFFER_TOO_SMALL is returned. @param[in] Augend A number to which addend will be added @param[in] Addend A number to be added to another @param[out] Result Pointer to the result of addition @retval RETURN_SUCCESS Successful addition @retval RETURN_BUFFER_TOO_SMALL Overflow @retval RETURN_INVALID_PARAMETER Result is NULL **/ RETURN_STATUS EFIAPI SafeUintnAdd ( IN UINTN Augend, IN UINTN Addend, OUT UINTN *Result ) { RETURN_STATUS Status; if (Result == NULL) { return RETURN_INVALID_PARAMETER; } if (sizeof (UINTN) == sizeof (UINT32)) { if ((UINT32)(Augend + Addend) >= Augend) { *Result = (Augend + Addend); Status = RETURN_SUCCESS; } else { *Result = UINTN_ERROR; Status = RETURN_BUFFER_TOO_SMALL; } return Status; } return SafeUint64Add ((UINT64)Augend, (UINT64)Addend, (UINT64 *)Result); }
/** UINTN addition Performs the requested operation using the input parameters into a value specified by Result type and stores the converted value into the caller allocated output buffer specified by Result. The caller must pass in a Result buffer that is at least as large as the Result type. If Result is NULL, RETURN_INVALID_PARAMETER is returned. If the requested operation results in an overflow or an underflow condition, then Result is set to UINTN_ERROR and RETURN_BUFFER_TOO_SMALL is returned. @param[in] Augend A number to which addend will be added @param[in] Addend A number to be added to another @param[out] Result Pointer to the result of addition @retval RETURN_SUCCESS Successful addition @retval RETURN_BUFFER_TOO_SMALL Overflow @retval RETURN_INVALID_PARAMETER Result is NULL **/ RETURN_STATUS EFIAPI SafeUintnAdd ( IN UINTN Augend, IN UINTN Addend, OUT UINTN *Result ) { return SafeUint64Add ((UINT64)Augend, (UINT64)Addend, (UINT64 *)Result); }