chsvlib
chsv helper source code

◆ PrintfA_s()

int Chusov::String::PrintfA_s ( const char *restrict  pszFormat,
  ... 
)
noexcept

The function behaves identically to PrintfA but with security constraints.

Parameters
[in]pszFormatis a pointer to a zero terminated string defining how to interpret data, passed as additional parameters, during the construction of the output. See PrintfA for the definition of the format lexemes considering the runtime constraints described in the remarks below.
...constitute an optional set of additional parameters to build the formatted output according to pszFormat.
Returns
On success the function returns a number of bytes of the output not counting the terminating zero. If an output, encoding or runtime constraint violation error occurs the function returns a negative value.

The function behaves identically to PrintfA following the same rules of specifying conversion specifications with some exceptions. These exceptions are introduced with respect to the ISO/IEC TR 24731-1 standard and defined as the following runtime constraints:

  1. The pszFormat pointer must not be a NULL pointer. Otherwise the function will generate an assertion and, if the execution is allowed to continue, will fail setting errno to EINVAL. This check is not performed by the PrintfA function so the latter will cause access violations in this case.
  2. The 'n' format type specifier is not allowed (modified or not by additional flags, width, precision, size). Otherwise the function will generate an assertion and, if the execution is allowed to continue, will fail setting errno to EINVAL. The specifier is allowed for PrintfA().
  3. Any pointer corresponding to the 's' or 'S' format type specifier must not be NULL. Otherwise the function will generate an assertion and, if the execution is allowed to continue, will fail setting errno to EINVAL. This kind of checks are also not performed by the PrintfA function. For example the call
      PrintfA("%.0s", NULL);
    
    will succeed while
      PrintfA_s("%.0s", NULL);
    
    will generate an assertion and cause the function failure.

The function implements security enhancements for the PrintfA function just like printf_s function, defined in the ISO/IEC TR 24731-1 standard, provides the same enhancements for the C99 printf function.

See also
PrintfA;
PrintfW_s;
vPrintfA_s.