safec  2.1
Safe C Library - ISO TR24731 Bounds Checking Interface
vsprintf_s.c File Reference
#include "config.h"
#include "safe_str_lib.h"
#include "safe_str_constraint.h"
#include <stdarg.h>
#include "safeclib_private.h"
+ Include dependency graph for vsprintf_s.c:

Go to the source code of this file.

Functions

int vsprintf_s (char *restrict dest, rsize_t dmax, const char *restrict fmt, va_list ap)
 The vsprintf_s function composes a string with same test that would be printed if format was used on printf. More...
 

Function Documentation

◆ vsprintf_s()

int vsprintf_s ( char *restrict  dest,
rsize_t  dmax,
const char *restrict  fmt,
va_list  ap 
)

The vsprintf_s function composes a string with same test that would be printed if format was used on printf.

Instead of being printed, the content is stored in dest. With SAFECLIB_STR_NULL_SLACK defined all elements following the terminating null character (if any) written by vsprintf_s in the array of dmax characters pointed to by dest are nulled when vsprintf_s returns.

Remarks
SPECIFIED IN
Parameters
[out]destpointer to string that will be written into.
[in]dmaxrestricted maximum length of dest
[in]fmtformat-control string.
[in]apoptional arguments
Precondition
Neither dest nor fmt shall be a null pointer.
dmax shall not be greater than RSIZE_MAX_STR.
dmax shall not equal zero.
dmax shall be greater than strnlen_s(dest, dmax).
fmt shall not contain the conversion specifier n
None of the arguments corresponding to s is a null pointer
No encoding error shall occur.
Note
C11 uses RSIZE_MAX, not RSIZE_MAX_STR.
Returns
On success the total number of characters written is returned.
On failure a negative number is returned.
If the buffer dest is too small for the formatted text, including the terminating null, then the buffer is set to an empty string by placing a null character at dest[0], and the invalid parameter handler is invoked. Unlike vsnprintf, vsprintf_s guarantees that the buffer will be null-terminated unless the buffer size is zero.
Return values
ESNULLPwhen dest/fmt is NULL pointer
ESZEROLwhen dmax = 0
ESLEMAXwhen dmax > RSIZE_MAX_STR
ESNOSPCwhen return value exceeds dmax
See also
sprintf_s(), vsnprintf_s()

Definition at line 91 of file vsprintf_s.c.