chsvlib
chsv helper source code

◆ vsPrintfW_s()

int Chusov::String::vsPrintfW_s ( wchar_t *restrict  pDest,
rsize_t  cchDest,
const wchar_t *restrict  pszFormat,
va_list  ap 
)
noexcept

The function behaves identically to vsPrintfW except for the explicit constraints listed in the remarks.

Parameters
[out]pDestis a pointer to the output buffer where the converted string is to be written to.
[in]cchDestis a size of the output buffer, in wide characters, including the terminating zero. Unlike vsnPrintfW_s the function treats buffer overrun as an error, failing and setting the errno code to ENOBUFS.
[in]pszFormatis a pointer to a zero terminated wide string defining how to interpret data, passed as additional parameters, during the construction of the output. See PrintfW_s for the definition of the format lexemes.
[in]apis a variable argument list containing data used to construct an output string according to the format.
Returns
On success the function returns a number of wide characters written to the buffer not counting the terminating zero. If an encoding error occurs or if cchDest is less than a size required to hold the complete output string, the function returns a negative value. If any other runtime constraint violation occurred, the function returns 0.

The function implements the behaviour of the vswprintf_s function that is described in the ISO/IEC TR 24731-1 standard offering security enhancements by specifying additional runtime constraints listed below.

  1. Neither pDest nor pszFormat can be NULL.
  2. The size cchDest must neither equal zero nor be greater than RSIZE_MAX nor be less than a size of the output string to be written, including the terminating null.
  3. The 'n' type specifier must not appear in a set of conversion specifiers (see PrintfA and PrintfA_s).
  4. Any pointer corresponding to 's' or 'S' type specifiers must not be NULL.

If any of the constraints is violated the function generates an assertion and, if the execution is allowed to continue, returns a negative number for the insufficient buffer error or zero for other errors, setting corresponding errno code. If an encoding error occurred the function also returns a negative number.

On error, if pDest is not null and cchDest is greater than 0 and less than RSIZE_MAX, the function sets pDest[0] to the null character.

The corresponding original C function is vswprintf that has a corresponding chsvlib implementation sPrintfW.

See also
PrintfW_s;
vsPrintfA_s;
vsPrintfW.