Share via


StringCbCatN (Windows CE 5.0)

Send Feedback

Developing an Application > Safe String Functions > Safe String Reference > StrSafe.h Byte-Count Functions

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.

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:

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

OS Versions: Windows CE 5.0 and later.
Header: strsafe.h.
Link Library: strsafe.lib.

See Also

StringCchCatN | StringCbCatNEx

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.