TianoCore EDK2 master
Loading...
Searching...
No Matches
SafeIntLibEbc.c File Reference
#include <Base.h>
#include <Library/SafeIntLib.h>

Go to the source code of this file.

Functions

RETURN_STATUS EFIAPI SafeInt32ToUintn (IN INT32 Operand, OUT UINTN *Result)
 
RETURN_STATUS EFIAPI SafeUint32ToIntn (IN UINT32 Operand, OUT INTN *Result)
 
RETURN_STATUS EFIAPI SafeIntnToInt32 (IN INTN Operand, OUT INT32 *Result)
 
RETURN_STATUS EFIAPI SafeIntnToUint32 (IN INTN Operand, OUT UINT32 *Result)
 
RETURN_STATUS EFIAPI SafeUintnToUint32 (IN UINTN Operand, OUT UINT32 *Result)
 
RETURN_STATUS EFIAPI SafeUintnToInt64 (IN UINTN Operand, OUT INT64 *Result)
 
RETURN_STATUS EFIAPI SafeInt64ToIntn (IN INT64 Operand, OUT INTN *Result)
 
RETURN_STATUS EFIAPI SafeInt64ToUintn (IN INT64 Operand, OUT UINTN *Result)
 
RETURN_STATUS EFIAPI SafeUint64ToUintn (IN UINT64 Operand, OUT UINTN *Result)
 
RETURN_STATUS EFIAPI SafeUintnAdd (IN UINTN Augend, IN UINTN Addend, OUT UINTN *Result)
 
RETURN_STATUS EFIAPI SafeUintnSub (IN UINTN Minuend, IN UINTN Subtrahend, OUT UINTN *Result)
 
RETURN_STATUS EFIAPI SafeUintnMult (IN UINTN Multiplicand, IN UINTN Multiplier, OUT UINTN *Result)
 
RETURN_STATUS EFIAPI SafeIntnAdd (IN INTN Augend, IN INTN Addend, OUT INTN *Result)
 
RETURN_STATUS EFIAPI SafeIntnSub (IN INTN Minuend, IN INTN Subtrahend, OUT INTN *Result)
 
RETURN_STATUS EFIAPI SafeIntnMult (IN INTN Multiplicand, IN INTN Multiplier, OUT INTN *Result)
 

Detailed Description

This library provides helper functions to prevent integer overflow during type conversion, addition, subtraction, and multiplication.

Copyright (c) 2017, Microsoft Corporation

All rights reserved. SPDX-License-Identifier: BSD-2-Clause-Patent

Definition in file SafeIntLibEbc.c.

Function Documentation

◆ SafeInt32ToUintn()

RETURN_STATUS EFIAPI SafeInt32ToUintn ( IN INT32  Operand,
OUT UINTN Result 
)

INT32 -> UINTN conversion

Converts the value specified by Operand to 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 conversion results in an overflow or an underflow condition, then Result is set to UINTN_ERROR and RETURN_BUFFER_TOO_SMALL is returned.

Parameters
[in]OperandOperand to be converted to new type
[out]ResultPointer to the result of conversion
Return values
RETURN_SUCCESSSuccessful conversion
RETURN_BUFFER_TOO_SMALLOverflow
RETURN_INVALID_PARAMETERResult is NULL

Definition at line 37 of file SafeIntLibEbc.c.

◆ SafeInt64ToIntn()

RETURN_STATUS EFIAPI SafeInt64ToIntn ( IN INT64  Operand,
OUT INTN Result 
)

INT64 -> INTN conversion

Converts the value specified by Operand to 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 conversion results in an overflow or an underflow condition, then Result is set to INTN_ERROR and RETURN_BUFFER_TOO_SMALL is returned.

Parameters
[in]OperandOperand to be converted to new type
[out]ResultPointer to the result of conversion
Return values
RETURN_SUCCESSSuccessful conversion
RETURN_BUFFER_TOO_SMALLOverflow
RETURN_INVALID_PARAMETERResult is NULL

Definition at line 275 of file SafeIntLibEbc.c.

◆ SafeInt64ToUintn()

RETURN_STATUS EFIAPI SafeInt64ToUintn ( IN INT64  Operand,
OUT UINTN Result 
)

INT64 -> UINTN conversion

Converts the value specified by Operand to 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 conversion results in an overflow or an underflow condition, then Result is set to UINTN_ERROR and RETURN_BUFFER_TOO_SMALL is returned.

Parameters
[in]OperandOperand to be converted to new type
[out]ResultPointer to the result of conversion
Return values
RETURN_SUCCESSSuccessful conversion
RETURN_BUFFER_TOO_SMALLOverflow
RETURN_INVALID_PARAMETERResult is NULL

Definition at line 314 of file SafeIntLibEbc.c.

◆ SafeIntnAdd()

RETURN_STATUS EFIAPI SafeIntnAdd ( IN INTN  Augend,
IN INTN  Addend,
OUT INTN Result 
)

INTN 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 INTN_ERROR and RETURN_BUFFER_TOO_SMALL is returned.

Parameters
[in]AugendA number to which addend will be added
[in]AddendA number to be added to another
[out]ResultPointer to the result of addition
Return values
RETURN_SUCCESSSuccessful addition
RETURN_BUFFER_TOO_SMALLOverflow
RETURN_INVALID_PARAMETERResult is NULL

Definition at line 528 of file SafeIntLibEbc.c.

◆ SafeIntnMult()

RETURN_STATUS EFIAPI SafeIntnMult ( IN INTN  Multiplicand,
IN INTN  Multiplier,
OUT INTN Result 
)

INTN multiplication

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 INTN_ERROR and RETURN_BUFFER_TOO_SMALL is returned.

Parameters
[in]MultiplicandA number that is to be multiplied by another
[in]MultiplierA number by which the multiplicand is to be multiplied
[out]ResultPointer to the result of multiplication
Return values
RETURN_SUCCESSSuccessful multiplication
RETURN_BUFFER_TOO_SMALLOverflow
RETURN_INVALID_PARAMETERResult is NULL

Definition at line 600 of file SafeIntLibEbc.c.

◆ SafeIntnSub()

RETURN_STATUS EFIAPI SafeIntnSub ( IN INTN  Minuend,
IN INTN  Subtrahend,
OUT INTN Result 
)

INTN Subtraction

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 INTN_ERROR and RETURN_BUFFER_TOO_SMALL is returned.

Parameters
[in]MinuendA number from which another is to be subtracted.
[in]SubtrahendA number to be subtracted from another
[out]ResultPointer to the result of subtraction
Return values
RETURN_SUCCESSSuccessful subtraction
RETURN_BUFFER_TOO_SMALLUnderflow
RETURN_INVALID_PARAMETERResult is NULL

Definition at line 564 of file SafeIntLibEbc.c.

◆ SafeIntnToInt32()

RETURN_STATUS EFIAPI SafeIntnToInt32 ( IN INTN  Operand,
OUT INT32 *  Result 
)

INTN -> INT32 conversion

Converts the value specified by Operand to 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 conversion results in an overflow or an underflow condition, then Result is set to INT32_ERROR and RETURN_BUFFER_TOO_SMALL is returned.

Parameters
[in]OperandOperand to be converted to new type
[out]ResultPointer to the result of conversion
Return values
RETURN_SUCCESSSuccessful conversion
RETURN_BUFFER_TOO_SMALLOverflow
RETURN_INVALID_PARAMETERResult is NULL

Definition at line 110 of file SafeIntLibEbc.c.

◆ SafeIntnToUint32()

RETURN_STATUS EFIAPI SafeIntnToUint32 ( IN INTN  Operand,
OUT UINT32 *  Result 
)

INTN -> UINT32 conversion

Converts the value specified by Operand to 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 conversion results in an overflow or an underflow condition, then Result is set to UINT32_ERROR and RETURN_BUFFER_TOO_SMALL is returned.

Parameters
[in]OperandOperand to be converted to new type
[out]ResultPointer to the result of conversion
Return values
RETURN_SUCCESSSuccessful conversion
RETURN_BUFFER_TOO_SMALLOverflow
RETURN_INVALID_PARAMETERResult is NULL

Definition at line 149 of file SafeIntLibEbc.c.

◆ SafeUint32ToIntn()

RETURN_STATUS EFIAPI SafeUint32ToIntn ( IN UINT32  Operand,
OUT INTN Result 
)

UINT32 -> INTN conversion

Converts the value specified by Operand to 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 conversion results in an overflow or an underflow condition, then Result is set to INTN_ERROR and RETURN_BUFFER_TOO_SMALL is returned.

Parameters
[in]OperandOperand to be converted to new type
[out]ResultPointer to the result of conversion
Return values
RETURN_SUCCESSSuccessful conversion
RETURN_BUFFER_TOO_SMALLOverflow
RETURN_INVALID_PARAMETERResult is NULL

Definition at line 71 of file SafeIntLibEbc.c.

◆ SafeUint64ToUintn()

RETURN_STATUS EFIAPI SafeUint64ToUintn ( IN UINT64  Operand,
OUT UINTN Result 
)

UINT64 -> UINTN conversion

Converts the value specified by Operand to 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 conversion results in an overflow or an underflow condition, then Result is set to UINTN_ERROR and RETURN_BUFFER_TOO_SMALL is returned.

Parameters
[in]OperandOperand to be converted to new type
[out]ResultPointer to the result of conversion
Return values
RETURN_SUCCESSSuccessful conversion
RETURN_BUFFER_TOO_SMALLOverflow
RETURN_INVALID_PARAMETERResult is NULL

Definition at line 348 of file SafeIntLibEbc.c.

◆ SafeUintnAdd()

RETURN_STATUS EFIAPI SafeUintnAdd ( IN UINTN  Augend,
IN UINTN  Addend,
OUT UINTN 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.

Parameters
[in]AugendA number to which addend will be added
[in]AddendA number to be added to another
[out]ResultPointer to the result of addition
Return values
RETURN_SUCCESSSuccessful addition
RETURN_BUFFER_TOO_SMALLOverflow
RETURN_INVALID_PARAMETERResult is NULL

Definition at line 388 of file SafeIntLibEbc.c.

◆ SafeUintnMult()

RETURN_STATUS EFIAPI SafeUintnMult ( IN UINTN  Multiplicand,
IN UINTN  Multiplier,
OUT UINTN Result 
)

UINTN multiplication

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.

Parameters
[in]MultiplicandA number that is to be multiplied by another
[in]MultiplierA number by which the multiplicand is to be multiplied
[out]ResultPointer to the result of multiplication
Return values
RETURN_SUCCESSSuccessful multiplication
RETURN_BUFFER_TOO_SMALLOverflow
RETURN_INVALID_PARAMETERResult is NULL

Definition at line 488 of file SafeIntLibEbc.c.

◆ SafeUintnSub()

RETURN_STATUS EFIAPI SafeUintnSub ( IN UINTN  Minuend,
IN UINTN  Subtrahend,
OUT UINTN Result 
)

UINTN subtraction

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.

Parameters
[in]MinuendA number from which another is to be subtracted.
[in]SubtrahendA number to be subtracted from another
[out]ResultPointer to the result of subtraction
Return values
RETURN_SUCCESSSuccessful subtraction
RETURN_BUFFER_TOO_SMALLUnderflow
RETURN_INVALID_PARAMETERResult is NULL

Definition at line 438 of file SafeIntLibEbc.c.

◆ SafeUintnToInt64()

RETURN_STATUS EFIAPI SafeUintnToInt64 ( IN UINTN  Operand,
OUT INT64 *  Result 
)

UINTN -> INT64 conversion

Converts the value specified by Operand to 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 conversion results in an overflow or an underflow condition, then Result is set to INT64_ERROR and RETURN_BUFFER_TOO_SMALL is returned.

Parameters
[in]OperandOperand to be converted to new type
[out]ResultPointer to the result of conversion
Return values
RETURN_SUCCESSSuccessful conversion
RETURN_BUFFER_TOO_SMALLOverflow
RETURN_INVALID_PARAMETERResult is NULL

Definition at line 236 of file SafeIntLibEbc.c.

◆ SafeUintnToUint32()

RETURN_STATUS EFIAPI SafeUintnToUint32 ( IN UINTN  Operand,
OUT UINT32 *  Result 
)

UINTN -> UINT32 conversion

Converts the value specified by Operand to 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 conversion results in an overflow or an underflow condition, then Result is set to UINT32_ERROR and RETURN_BUFFER_TOO_SMALL is returned.

Parameters
[in]OperandOperand to be converted to new type
[out]ResultPointer to the result of conversion
Return values
RETURN_SUCCESSSuccessful conversion
RETURN_BUFFER_TOO_SMALLOverflow
RETURN_INVALID_PARAMETERResult is NULL

Definition at line 197 of file SafeIntLibEbc.c.