Partager via


StringCbCatN (Windows Embedded CE 6.0)

1/5/2010

This function is a replacement for strncat.

The size, in bytes, of the destination buffer is provided to the function to ensure that StringCbCatN does not write past the end of this buffer.

Syntax

HRESULT StringCbCatN(      
    LPTSTR pszDest,
    size_t cbDest,
    LPCTSTR pszSrc,
    size_t cbMaxAppend
);

Parameters

  • pszDest
    [in, out] Pointer to a buffer containing the string that pszSrc is concatenated to, and which contains the entire resultant string.

    The string at pszSrc, up to cbMaxAppend bytes, is added to the end of the string at pszDest.

  • cbDest
    [in] Size of the destination buffer, in bytes.

    This value must consider the length of pszSrc, plus the length of pszDest or cbMaxAppend (whichever is smaller), plus the terminating null character.

    The maximum number of bytes allowed is STRSAFE_MAX_CCH * sizeof(TCHAR).

  • pszSrc
    [in] Pointer to a buffer containing the source string that is concatenated to the end of pszDest.

    This source string must be null-terminated.

  • cbMaxAppend
    [in] The maximum number of bytes to append to pszDest.

Return Value

This function returns an HRESULT, as opposed to strncat, which returns a pointer. It is strongly recommended that you use the SUCCEEDED and FAILED macros to test the return value of this function.

Value Description

S_OK

Source data was present, the strings were concatenated without truncation, and the resultant destination buffer is null-terminated.

STRSAFE_E_INVALID_PARAMETER

The value in cbDest is larger than the maximum allowed value, or the destination buffer is full.

STRSAFE_E_INSUFFICIENT_BUFFER

The concatenation operation failed due to insufficient buffer space.

The destination buffer contains a truncated, null-terminated version of the intended result.

Where truncation is acceptable, this is not necessarily a failure condition.

Remarks

StringCbCatN provides additional processing for proper buffer handling in your code.

Poor buffer handling is implicated in many security issues that involve buffer overruns. StringCbCatN always null-terminates a nonzero-length destination buffer.

StringCbCatN can be used in its generic form, or specifically as StringCbCatNA (for ANSI strings) or StringCbCatNW (for Unicode strings). The form to use is determined by your data.

String data type String literal Function

char

"string"

StringCbCatNA

TCHAR

TEXT("string")

StringCbCatN

WCHAR

L"string"

StringCbCatNW

StringCbCatN and its ANSI and Unicode variants are replacements for these functions:

  • strncat
  • StrNCat

Behavior is undefined if the strings pointed to by pszSrc and pszDest overlap.

Neither pszSrc nor pszDest should be NULL.

If you need the handling of null string pointer values, see StringCbCatNEx.

Requirements

Header strsafe.h
Windows Embedded CE Windows CE 5.0 and later

See Also

Reference

StrSafe.h Byte-Count Functions
StringCchCatN
StringCbCatNEx