chsvlib
chsv helper source code

◆ vsPrintfA_s()

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

The function behaves identically to vsPrintfA except for the parameter cchDest and 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 bytes, including the terminating zero. Unlike vsnPrintfA_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 multibyte string defining how to interpret data, passed as additional parameters, during the construction of the output. See PrintfA_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 bytes written to the buffer not counting the terminating zero. If an encoding error occurs the function returns a negative value. If any other runtime constraint violation occurred, the function returns 0.

The function implements the behaviour of the vsprintf_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 zero number setting corresponding errno code. If an encoding error occurred the function 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 vsprintf that has a corresponding chsvlib implementation sPrintfA.

See also
PrintfA_s;
vsPrintfW_s;
vsPrintfA.