Defined in carb/extras/StringSafe.h

inline size_t carb::extras::formatStringV(char *dstBuf, size_t dstBufSize, const char *fmtString, va_list argsList)

A vsnprintf wrapper that clamps the return value.


This function is intended to be used in code where an index is incremented by snprintf. In the following example, if vsnprintf() were used, idx can become larger than len, causing wraparound errors, but with formatStringV(), idx will never become larger than len.

          idx += formatStringV(buf, len - idx, ...);
          idx += formatStringV(buf, len - idx, ...);

  • dstBuf[out] pointer to a destination buffer (can be nullptr in the case if dstBufSize is zero).

  • dstBufSize[in] size in characters of the destination buffer.

  • fmtString[in] pointer to a format string (passed to the vsnprintf call).

  • argsList[in] arguments list


a number of characters written to the destination buffer (not including the trailing \0).