RtlUShortSub - NtDoc

Native API online documentation, based on the System Informer (formerly Process Hacker) phnt headers
#ifndef _NTINTSAFE_H_INCLUDED_
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_SYSTEM | WINAPI_PARTITION_GAMES)

//
// USHORT subtraction
//
_Must_inspect_result_
__inline
NTSTATUS
RtlUShortSub(
    _In_ USHORT usMinuend,
    _In_ USHORT usSubtrahend,
    _Out_ _Deref_out_range_(==, usMinuend - usSubtrahend) USHORT* pusResult)
{
    NTSTATUS status;

    if (usMinuend >= usSubtrahend)
    {
        *pusResult = (USHORT)(usMinuend - usSubtrahend);
        status = STATUS_SUCCESS;
    }
    else
    {
        *pusResult = USHORT_ERROR;
        status = STATUS_INTEGER_OVERFLOW;
    }

    return status;
}

#endif
#endif

View code on GitHub
// ntintsafe.h

NTSTATUS RtlUShortSub(
  [in]  USHORT usMinuend,
  [in]  USHORT usSubtrahend,
  [out] USHORT *pusResult
);
View the official Windows Driver Kit DDI reference

NtDoc

No description available.

Windows Driver Kit DDI reference (nf-ntintsafe-rtlushortsub)

RtlUShortSub function

Description

Subtracts one value of type USHORT from another.

Parameters

usMinuend [in]

The value from which usSubtrahend is subtracted.

usSubtrahend [in]

The value to subtract from usMinuend.

pusResult [out]

A pointer to the result. If the operation results in a value that overflows or underflows the capacity of the type, the function returns STATUS_INTEGER_OVERFLOW and this parameter is not valid.

Return value

Returns STATUS_SUCCESS if the operation is successful.

See the implementation of this helper function in ntintsafe.h in the WDK for possible error return values.

Remarks

This is one of a set of inline functions designed to provide arithmetic operations and perform validity checks with minimal impact on performance.